Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Bug 1236367 - Clean up the codebase for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki committed Jan 4, 2016
1 parent c82fb1d commit bcf3950
Show file tree
Hide file tree
Showing 56 changed files with 180 additions and 276 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -94,7 +94,7 @@
"dot-location": [2, "property"],
"no-implied-eval": 2,
"no-loop-func": 2,
"no-magic-numbers": 1,
"no-magic-numbers": [1, {"ignore": [-1, 0, 1, 2]}],
"no-useless-call": 1,
"no-useless-concat": 1,
"no-delete-var": 2,
Expand Down Expand Up @@ -134,7 +134,7 @@
"prefer-const": 1,
"prefer-spread": 2,
"strict": [2, "global"],
"indent": [1, 2]
"indent": [1, 2, {"SwitchCase": 1}]
}
}
}
2 changes: 1 addition & 1 deletion src/.jshintrc
Expand Up @@ -11,7 +11,7 @@
"noarg": true,
"noempty": true,
"nonew": true,
"strict": true,
"strict": false,
"globalstrict": true,
"trailing": true,
"undef": true,
Expand Down
2 changes: 0 additions & 2 deletions src/bindings/gaiabuild/legacy/context.js
@@ -1,5 +1,3 @@
'use strict';

import { Context } from '../../../lib/context';
import { format } from './resolver';

Expand Down
2 changes: 0 additions & 2 deletions src/bindings/gaiabuild/legacy/env.js
@@ -1,5 +1,3 @@
'use strict';

import { L10nError } from '../../../lib/errors';
import { Env } from '../../../lib/env';
import { LegacyContext } from './context';
Expand Down
44 changes: 21 additions & 23 deletions src/bindings/gaiabuild/legacy/parser.js
@@ -1,8 +1,6 @@
'use strict';

import { L10nError } from '../../../lib/errors';

var MAX_PLACEABLES = 100;
const MAX_PLACEABLES = 100;

export default {
patterns: null,
Expand All @@ -26,15 +24,15 @@ export default {
this.init();
}

var ast = [];
const ast = [];
this.entryIds = Object.create(null);

var entries = source.match(this.patterns.entries);
const entries = source.match(this.patterns.entries);
if (!entries) {
return ast;
}
for (var i = 0; i < entries.length; i++) {
var line = entries[i];
for (let i = 0; i < entries.length; i++) {
let line = entries[i];

if (this.patterns.comment.test(line)) {
continue;
Expand All @@ -44,7 +42,7 @@ export default {
line = line.slice(0, -1) + entries[++i].trim();
}

var entityMatch = line.match(this.patterns.entity);
const entityMatch = line.match(this.patterns.entity);
if (entityMatch) {
try {
this.parseEntity(entityMatch[1], entityMatch[2], ast);
Expand All @@ -61,9 +59,9 @@ export default {
},

parseEntity: function(id, value, ast) {
var name, key;
let name, key;

var pos = id.indexOf('[');
const pos = id.indexOf('[');
if (pos !== -1) {
name = id.substr(0, pos);
key = id.substring(pos + 1, id.length - 1);
Expand All @@ -72,14 +70,14 @@ export default {
key = null;
}

var nameElements = name.split('.');
const nameElements = name.split('.');

if (nameElements.length > 2) {
throw new L10nError('Error in ID: "' + name + '".' +
' Nested attributes are not supported.');
}

var attr;
let attr;
if (nameElements.length > 1) {
name = nameElements[0];
attr = nameElements[1];
Expand All @@ -95,9 +93,9 @@ export default {
},

setEntityValue: function(id, attr, key, rawValue, ast) {
var pos, v;
let pos, v;

var value = rawValue.indexOf('{{') > -1 ?
const value = rawValue.indexOf('{{') > -1 ?
this.parseString(rawValue) : rawValue;

if (attr) {
Expand Down Expand Up @@ -152,18 +150,18 @@ export default {
},

parseString: function(str) {
var chunks = str.split(this.patterns.placeables);
var complexStr = [];
const chunks = str.split(this.patterns.placeables);
const complexStr = [];

var len = chunks.length;
var placeablesCount = (len - 1) / 2;
const len = chunks.length;
const placeablesCount = (len - 1) / 2;

if (placeablesCount >= MAX_PLACEABLES) {
throw new L10nError('Too many placeables (' + placeablesCount +
', max allowed is ' + MAX_PLACEABLES + ')');
}

for (var i = 0; i < chunks.length; i++) {
for (let i = 0; i < chunks.length; i++) {
if (chunks[i].length === 0) {
continue;
}
Expand All @@ -180,13 +178,13 @@ export default {
if (str.lastIndexOf('\\') !== -1) {
str = str.replace(this.patterns.controlChars, '$1');
}
return str.replace(this.patterns.unicode, function(match, token) {
return String.fromCodePoint(parseInt(token, 16));
});
return str.replace(this.patterns.unicode,
(match, token) => String.fromCodePoint(parseInt(token, 16))
);
},

parseIndex: function(str) {
var match = str.match(this.patterns.index);
const match = str.match(this.patterns.index);
if (!match) {
throw new L10nError('Malformed index');
}
Expand Down
2 changes: 0 additions & 2 deletions src/bindings/gaiabuild/legacy/pseudo.js
@@ -1,5 +1,3 @@
'use strict';

// Recursively walk an AST node searching for content leaves
export function walkContent(node, fn) {
if (typeof node === 'string') {
Expand Down
54 changes: 26 additions & 28 deletions src/bindings/gaiabuild/legacy/resolver.js
@@ -1,5 +1,3 @@
'use strict';

import { L10nError } from '../../../lib/errors';

const KNOWN_MACROS = ['plural'];
Expand Down Expand Up @@ -145,42 +143,42 @@ function subPlaceable(locals, ctx, lang, args, id) {
}

function interpolate(locals, ctx, lang, args, arr) {
return arr.reduce(function([localsSeq, valueSeq], cur) {
return arr.reduce(([localsSeq, valueSeq], cur) => {
if (typeof cur === 'string') {
return [localsSeq, valueSeq + cur];
} else if (cur.t === 'idOrVar'){
} else if (cur.t === 'idOrVar') {
const [, value] = subPlaceable(locals, ctx, lang, args, cur.v);
return [localsSeq, valueSeq + value];
}
}, [locals, '']);
}

function resolveSelector(ctx, lang, args, expr, index) {
const selectorName = index[0].v;
const selector = resolveIdentifier(ctx, lang, args, selectorName)[1];
const selectorName = index[0].v;
const selector = resolveIdentifier(ctx, lang, args, selectorName)[1];

if (typeof selector !== 'function') {
// selector is a simple reference to an entity or args
return selector;
}
if (typeof selector !== 'function') {
// selector is a simple reference to an entity or args
return selector;
}

const argValue = index[1] ?
resolveIdentifier(ctx, lang, args, index[1])[1] : undefined;

const argValue = index[1] ?
resolveIdentifier(ctx, lang, args, index[1])[1] : undefined;

if (selectorName === 'plural') {
// special cases for zero, one, two if they are defined on the hash
if (argValue === 0 && 'zero' in expr) {
return 'zero';
}
if (argValue === 1 && 'one' in expr) {
return 'one';
}
if (argValue === 2 && 'two' in expr) {
return 'two';
}
if (selectorName === 'plural') {
// special cases for zero, one, two if they are defined on the hash
if (argValue === 0 && 'zero' in expr) {
return 'zero';
}
if (argValue === 1 && 'one' in expr) {
return 'one';
}
if (argValue === 2 && 'two' in expr) {
return 'two';
}
}

return selector(argValue);
return selector(argValue);
}

function resolveValue(locals, ctx, lang, args, expr, index) {
Expand All @@ -195,9 +193,9 @@ function resolveValue(locals, ctx, lang, args, expr, index) {
}

if (Array.isArray(expr)) {
locals.contextIsNonLatin1 = expr.some(function($_) {
return typeof($_) === 'string' && $_.match(nonLatin1);
});
locals.contextIsNonLatin1 = expr.some(
$_ => typeof($_) === 'string' && $_.match(nonLatin1)
);
return interpolate(locals, ctx, lang, args, expr);
}

Expand Down
8 changes: 3 additions & 5 deletions src/bindings/gaiabuild/legacy/serialize.js
@@ -1,5 +1,3 @@
'use strict';

import { L10nError } from '../../../lib/errors';

export function serializeLegacyContext(ctx) {
Expand All @@ -24,13 +22,13 @@ function serializeEntries(lang, langEntries, sourceEntries) {

if (!langEntry) {
errors.push(new L10nError(
'"' + id + '"' + ' not found in ' + lang.code, id, lang));
'"' + id + '" not found in ' + lang.code, id, lang));
return serializeEntry(sourceEntry, id);
}

if (!areEntityStructsEqual(sourceEntry, langEntry)) {
errors.push(new L10nError(
'"' + id + '"' + ' is malformed in ' + lang.code, id, lang));
'"' + id + '" is malformed in ' + lang.code, id, lang));
return serializeEntry(sourceEntry, id);
}

Expand All @@ -57,7 +55,7 @@ function serializeEntry(entry, id) {
node.$x = entry.index;
}

for (let key in entry.attrs) {
for (const key in entry.attrs) {
node[key] = serializeAttribute(entry.attrs[key]);
}

Expand Down
8 changes: 3 additions & 5 deletions src/bindings/gaiabuild/serialize.js
@@ -1,5 +1,3 @@
'use strict';

import { L10nError } from '../../lib/errors';

export function serializeContext(ctx) {
Expand All @@ -20,20 +18,20 @@ function serializeEntries(lang, langEntries, sourceEntries) {
const errors = [];
const entries = Object.create(null);

for (let id in sourceEntries) {
for (const id in sourceEntries) {
const sourceEntry = sourceEntries[id];
const langEntry = langEntries[id];

if (!langEntry) {
errors.push(new L10nError(
'"' + id + '"' + ' not found in ' + lang.code, id, lang));
'"' + id + '" not found in ' + lang.code, id, lang));
entries[id] = sourceEntry;
continue;
}

if (!areEntityStructsEqual(sourceEntry, langEntry)) {
errors.push(new L10nError(
'"' + id + '"' + ' is malformed in ' + lang.code, id, lang));
'"' + id + '" is malformed in ' + lang.code, id, lang));
entries[id] = sourceEntry;
continue;
}
Expand Down
2 changes: 0 additions & 2 deletions src/bindings/gaiabuild/view.js
@@ -1,5 +1,3 @@
'use strict';

import { pseudo } from '../../lib/pseudo';
import { Env } from '../../lib/env';
import { LegacyEnv } from './legacy/env';
Expand Down
6 changes: 2 additions & 4 deletions src/bindings/html/dom.js
@@ -1,5 +1,3 @@
'use strict';

import { disconnect, reconnect } from './observer';
import { overlayElement } from './overlay';

Expand Down Expand Up @@ -38,13 +36,13 @@ function getTranslatables(element) {
export function translateMutations(view, mutations) {
const targets = new Set();

for (let mutation of mutations) {
for (const mutation of mutations) {
switch (mutation.type) {
case 'attributes':
targets.add(mutation.target);
break;
case 'childList':
for (let addedNode of mutation.addedNodes) {
for (const addedNode of mutation.addedNodes) {
if (addedNode.nodeType === addedNode.ELEMENT_NODE) {
if (addedNode.childElementCount) {
getTranslatables(addedNode).forEach(targets.add.bind(targets));
Expand Down
10 changes: 4 additions & 6 deletions src/bindings/html/head.js
@@ -1,5 +1,3 @@
'use strict';

export function getResourceLinks(head) {
return Array.prototype.map.call(
head.querySelectorAll('link[rel="localization"]'),
Expand All @@ -16,7 +14,7 @@ export function getMeta(head) {
'meta[name="availableLanguages"],' +
'meta[name="defaultLanguage"],' +
'meta[name="appVersion"]'));
for (let meta of metas) {
for (const meta of metas) {
const name = meta.getAttribute('name');
const content = meta.getAttribute('content').trim();
switch (name) {
Expand Down Expand Up @@ -44,10 +42,10 @@ export function getMeta(head) {
}

function getLangRevisionMap(seq, str) {
return str.split(',').reduce((seq, cur) => {
return str.split(',').reduce((prevSeq, cur) => {
const [lang, rev] = getLangRevisionTuple(cur);
seq[lang] = rev;
return seq;
prevSeq[lang] = rev;
return prevSeq;
}, seq);
}

Expand Down
2 changes: 0 additions & 2 deletions src/bindings/html/langs.js
@@ -1,5 +1,3 @@
'use strict';

import { prioritizeLocales } from '../../lib/intl';
import { pseudo } from '../../lib/pseudo';

Expand Down
2 changes: 0 additions & 2 deletions src/bindings/html/observer.js
@@ -1,5 +1,3 @@
'use strict';

import { translateFragment, translateMutations } from './dom';

const observerConfig = {
Expand Down

0 comments on commit bcf3950

Please sign in to comment.