Skip to content

Commit

Permalink
style: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Oct 20, 2017
1 parent 5ccb8cf commit c363428
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 25 deletions.
30 changes: 30 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extends: eslint:recommended
env:
node: true
browser: true
rules:
block-scoped-var: 2
callback-return: 2
complexity: [2, 13]
curly: [2, multi-or-nest, consistent]
dot-location: [2, property]
dot-notation: 2
indent-legacy: [2, 2, SwitchCase: 1]
linebreak-style: [2, unix]
new-cap: 2
no-console: [2, allow: [warn, error]]
no-else-return: 2
no-eq-null: 2
no-fallthrough: 2
no-invalid-this: 2
no-return-assign: 2
no-shadow: 1
no-trailing-spaces: 2
no-use-before-define: [2, nofunc]
quotes: [2, single, avoid-escape]
semi: [2, always]
strict: [2, global]
valid-jsdoc: [2, requireReturn: false]
no-control-regex: 0
no-useless-escape: 2
no-tabs: 2
22 changes: 11 additions & 11 deletions messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,18 +584,18 @@ module.exports = {
zh: '应当有属性匹配模式 {{=e.params.missingPattern}}'
},
switch: {
en: 'should pass \"switch\" keyword validation, case {{=e.params.caseIndex}} fails',
ar: 'يجب أن تمرر كلمة التحقق المفتاحية \"switch\"، الحالة {{=e.params.caseIndex}} خاطئة',
cz: 'musí projít validácí \"switch\", případ {{=e.params.caseIndex}} je neúspěšný',
de: 'sollte der \"switch\" Validierung entsprechen, der Fall {{=e.params.caseIndex}} schlägt fehl',
es: 'debe pasar la validación \"switch\" de palabra clave, el caso {{=e.params.caseIndex}} falló',
fr: 'doit être valide selon le critère \"switch\":validation par mot-clé, le cas {{=e.params.caseIndex}} est invalide',
no: 'må passere \"switch\" validering, tilfellet {{=e.params.caseIndex}} misslykkes',
pl: 'powinien przejść walidacje pola \"switch\", przypadek {{=e.params.caseIndex}} zawiódł',
'pt-BR': 'deve passar a validação \"switch\" de palavra-chave, o caso {{=e.params.caseIndex}} falha',
en: 'should pass "switch" keyword validation, case {{=e.params.caseIndex}} fails',
ar: 'يجب أن تمرر كلمة التحقق المفتاحية "switch"، الحالة {{=e.params.caseIndex}} خاطئة',
cz: 'musí projít validácí "switch", případ {{=e.params.caseIndex}} je neúspěšný',
de: 'sollte der "switch" Validierung entsprechen, der Fall {{=e.params.caseIndex}} schlägt fehl',
es: 'debe pasar la validación "switch" de palabra clave, el caso {{=e.params.caseIndex}} falló',
fr: 'doit être valide selon le critère "switch":validation par mot-clé, le cas {{=e.params.caseIndex}} est invalide',
no: 'må passere "switch" validering, tilfellet {{=e.params.caseIndex}} misslykkes',
pl: 'powinien przejść walidacje pola "switch", przypadek {{=e.params.caseIndex}} zawiódł',
'pt-BR': 'deve passar a validação "switch" de palavra-chave, o caso {{=e.params.caseIndex}} falha',
ru: 'должно соответствовать правилу {{=e.params.caseIndex}} в "switch"',
sk: 'musí prejsť validáciou \"switch\", prípad {{=e.params.caseIndex}} je neúspešný',
sv: 'bör passera \"switch\" nyckelord validering, fallet {{=e.params.caseIndex}} misslyckas',
sk: 'musí prejsť validáciou "switch", prípad {{=e.params.caseIndex}} je neúspešný',
sv: 'bör passera "switch" nyckelord validering, fallet {{=e.params.caseIndex}} misslyckas',
zh: '由于 {{=e.params.caseIndex}} 失败,未通过 "switch" 校验, '
},
const: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"bundle-test": "npm run browserify-test && npm run uglify-test",
"browserify": "mkdir -p dist/ && browserify -r ./localize/index -o dist/ajv-i18n.bundle.js",
"browserify-test": "mkdir -p dist/ && browserify -r ./node_modules/ajv/lib/ajv.js:ajv -r ./localize/index -o dist/ajv-i18n.test.bundle.js",
"eslint": "eslint messages scripts spec/*.js",
"uglify": "uglifyjs ./dist/ajv-i18n.bundle.js -o ./dist/ajv-i18n.min.js -m -c --warn",
"uglify-test": "uglifyjs ./dist/ajv-i18n.test.bundle.js -o ./dist/ajv-i18n.test.min.js -m -c --warn",
"prepublish": "npm run build",
"test": "npm run build && npm run test-cov && npm run test-browser",
"test": "npm run eslint && npm run build && npm run test-cov && npm run test-browser",
"test-spec": "mocha spec/*.spec.js -R spec",
"test-cov": "nyc npm run test-spec",
"test-browser": "npm run bundle-test && scripts/prepare-tests && karma start --single-run --browsers PhantomJS"
Expand Down Expand Up @@ -45,6 +46,7 @@
"browserify": "^14.1.0",
"coveralls": "^3.0.0",
"dot": "^1.0.3",
"eslint": "^4.9.0",
"js-beautify": "^1.7.4",
"json-schema-test": "^1.3.0",
"karma": "^1.5.0",
Expand Down
4 changes: 4 additions & 0 deletions scripts/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules:
no-console: 0
no-empty: [2, allowEmptyCatch: true]
dot-notation: [2, allowPattern: "^en$"]
2 changes: 1 addition & 1 deletion scripts/compile-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function localeMessages(locale) {

locMsgs.sort(byKeyword);
return locMsgs;
};
}


function getLocalDefs(defs, locale) {
Expand Down
3 changes: 3 additions & 0 deletions spec/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globals:
describe: false
it: false
24 changes: 12 additions & 12 deletions spec/localize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var localize = require('../localize');

var jsonSchemaTest = require('json-schema-test');
var Ajv = require('ajv');
var ajvKeywords = require('ajv-keywords')
var ajvKeywords = require('ajv-keywords');
var assert = require('assert');

var remoteRefs = {
Expand All @@ -15,7 +15,7 @@ var remoteRefs = {
};

var suites = testSuites();
for (var suite in suites) runTests(suite);
for (var s in suites) runTests(s);

function runTests(suite) {
var instances = [
Expand All @@ -27,9 +27,8 @@ function runTests(suite) {

instances.forEach(function (ajv) {
addRemoteRefs(ajv);
if (suite != 'draft-06') {
if (suite != 'draft-06')
ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
}
});

var tests = {};
Expand All @@ -55,35 +54,36 @@ function getAjv(allErrors, verbose) {
patternGroups: true,
unknownFormats: ['allowedUnknown'],
allErrors: allErrors,
verbose: allErrors
verbose: verbose
});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
ajvKeywords(ajv, ['switch', 'patternRequired', 'formatMinimum', 'formatMaximum']);
ajv.addKeyword('constant', { macro: function(x) { return { const: x }; } })
ajv.addKeyword('constant', { macro: function(x) { return { const: x }; } });
return ajv;
}


function testSuites() {
var _suites;
if (typeof window == 'object') {
var suites = {
_suites = {
'draft-04': require('./JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json', {mode: 'list'}),
'draft-06': require('./JSON-Schema-Test-Suite/tests/draft6/{**/,}*.json', {mode: 'list'}),
'ajv tests': require('./ajv/spec/v5/*.json', {mode: 'list'})
};
for (var suiteName in suites) {
suites[suiteName].forEach(function(suite) {
for (var suiteName in _suites) {
_suites[suiteName].forEach(function(suite) {
suite.test = suite.module;
});
}
} else {
var suites = {
_suites = {
'draft-04': './JSON-Schema-Test-Suite/tests/draft4/{**/,}*.json',
'draft-06': './JSON-Schema-Test-Suite/tests/draft6/{**/,}*.json',
'ajv tests': './ajv/spec/v5/*.json'
}
};
}
return suites;
return _suites;
}

function afterEach(res) {
Expand Down

0 comments on commit c363428

Please sign in to comment.