Skip to content

Commit

Permalink
Merge 6679035 into 1a5c8ce
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sturgeon committed Mar 6, 2018
2 parents 1a5c8ce + 6679035 commit d9a19ff
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 154 deletions.
74 changes: 0 additions & 74 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@
"before": true
}
],
"block-scoped-var": "off",
"block-spacing": "error",
"brace-style": [
"error",
"stroustrup"
],
"callback-return": "off",
"camelcase": "error",
"class-methods-use-this": "error",
"comma-dangle": "error",
"comma-spacing": "off",
"comma-style": [
"error",
"last"
],
"complexity": "off",
"computed-property-spacing": [
"error",
"never"
],
"consistent-return": "off",
"consistent-this": "error",
"curly": "off",
"default-case": "error",
"dot-location": [
"error",
Expand All @@ -58,73 +51,45 @@
}
],
"eol-last": "error",
"eqeqeq": "off",
"func-call-spacing": "error",
"func-name-matching": "off",
"func-names": "off",
"generator-star-spacing": "off",
"global-require": "off",
"guard-for-in": "off",
"handle-callback-err": "off",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"indent": "off",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"keyword-spacing": "off",
"line-comment-position": "off",
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "error",
"lines-around-directive": "error",
"max-depth": "off",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "error",
"multiline-ternary": [
"error",
"never"
],
"new-parens": "error",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-catch-shadow": "off",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "error",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-empty-function": "off",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "off",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
Expand All @@ -134,45 +99,32 @@
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "off",
"no-loop-func": "off",
"no-magic-numbers": "off",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-negated-condition": "error",
"no-nested-ternary": "off",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-proto": "error",
"no-prototype-builtins": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "off",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "off",
"no-tabs": "off",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
Expand All @@ -188,70 +140,44 @@
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-unused-vars": "warn",
"no-use-before-define": "off",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-var": "off",
"no-void": "error",
"no-warning-comments": "off",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": "error",
"object-curly-spacing": "off",
"object-property-newline": [
"error",
{
"allowMultiplePropertiesPerLine": true
}
],
"object-shorthand": "off",
"one-var": "off",
"one-var-declaration-per-line": "error",
"operator-assignment": "off",
"operator-linebreak": "off",
"padded-blocks": "off",
"prefer-arrow-callback": "off",
"prefer-const": "off",
"prefer-numeric-literals": "error",
"prefer-reflect": "off",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "off",
"quote-props": "off",
"quotes": "off",
"radix": "error",
"require-jsdoc": "off",
"require-yield": "off",
"rest-spread-spacing": "error",
"semi": "off",
"semi-spacing": "error",
"sort-imports": "error",
"sort-keys": "off",
"sort-vars": "error",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "off",
"space-unary-ops": "error",
"spaced-comment": "off",
"strict": "error",
"symbol-description": "error",
"template-curly-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "off",
"vars-on-top": "off",
"wrap-iife": "error",
"wrap-regex": "off",
"yield-star-spacing": "error",
"yoda": [
"error",
Expand Down
6 changes: 0 additions & 6 deletions lib/common.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
'use strict';

const fs = require('fs');
const url = require('url');

const fetch = require('node-fetch');
const yaml = require('js-yaml');
const recurse = require('reftools/lib/recurse.js').recurse;
const jptr = require('reftools/lib/jptr.js').jptr;
const resolveInternal = jptr;
const clone = require('reftools/lib/clone.js').clone;

function hasDuplicates(array) {
Expand Down
59 changes: 34 additions & 25 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function deepMergeRules(ruleNickname, skipRules, rules = []) {
const content = fs.readFileSync(ruleFile, 'utf8');
const data = yaml.safeLoad(content, { json: true });

if (typeof data['require'] == 'string') {
rules = deepMergeRules(data['require'], rules);
if (typeof data.require == 'string') {
rules = deepMergeRules(data.require, rules);
}

for (const r in data['rules']) {
const rule = data['rules'][r];
for (const r in data.rules) {
const rule = data.rules[r];
if (!rule.enabled) continue;
if (skipRules.indexOf(rule.name) !== -1) continue;
if (!Array.isArray(rule.object)) rule.object = [ rule.object ];
if (!Array.isArray(rule.object)) rule.object = [rule.object];
if (rule.alphabetical && rule.alphabetical.properties && !Array.isArray(rule.alphabetical.properties)) {
rule.alphabetical.properties = [ rule.alphabetical.properties ];
rule.alphabetical.properties = [rule.alphabetical.properties];
}
if (rule.truthy && !Array.isArray(rule.truthy)) rule.truthy = [ rule.truthy ];
if (rule.truthy && !Array.isArray(rule.truthy)) rule.truthy = [rule.truthy];
rules.push(rule);
}

Expand All @@ -45,11 +45,12 @@ function loadRules(loadFiles, skipRules = []) {
function ensureRule(context, rule, shouldAssertion, results) {
try {
shouldAssertion();
} catch (error) {
}
catch (error) {
// rethrow when not a lint error
if (!error.name || error.name !== "AssertionError") throw error;

var pointer = (context && context.length>0 ? context[context.length-1] : null);
const pointer = (context && context.length > 0 ? context[context.length-1] : null);
const result = { pointer, rule, error };
results.push(result);
}
Expand Down Expand Up @@ -86,17 +87,20 @@ function lint(objectName, object, options = {}) {

// If we aren't expecting an object keyed by a specific property, then treat the
// object as a simple array.
if (!rule.alphabetical.keyedBy) {
arrayCopy.sort()
} else {
if (rule.alphabetical.keyedBy) {
const keyedBy = [rule.alphabetical.keyedBy];
arrayCopy.sort(function (a, b) {
if (a[keyedBy] < b[keyedBy]) {
return -1;
} else if (a[keyedBy] > b[keyedBy]) {
}
else if (a[keyedBy] > b[keyedBy]) {
return 1;
}
})
return 0;
});
}
else {
arrayCopy.sort()
}
ensure(rule, () => {
object.should.have.property(property);
Expand Down Expand Up @@ -135,36 +139,41 @@ function lint(objectName, object, options = {}) {
});
}
if (rule.pattern) {
const { omit, property, split, value } = rule.pattern;
const target = object[property]

let components = [];
if (rule.pattern.split) {
components = object[rule.pattern.property].split(rule.pattern.split);
if (split) {
components = target.split(split);
}
else {
components.push(object[rule.pattern.property]);
components.push(target);
}
const re = new RegExp(rule.pattern.value);
const re = new RegExp(value);
for (let component of components) {
if (rule.pattern.omit) component = component.split(rule.pattern.omit).join('');
if (omit) component = component.split(omit).join('');
if (component) {
ensure(rule, () => {
should(re.test(component)).be.exactly(true,rule.description);
should(re.test(component)).be.exactly(true, rule.description);
});
}
}
}
if (rule.notContain) {
for (const property of rule.notContain.properties) {
const { value, properties } = rule.notContain;
for (const property of properties) {
if (object[property] && (typeof object[property] === 'string') &&
(object[property].indexOf(rule.notContain.value)>=0)) {
(object[property].indexOf(value) >= 0)) {
ensure(rule, () => {
should.fail(true,false,rule.description);
});
}
}
}
if (rule.notEndWith) {
const { value, property } = rule.notEndWith;
ensure(rule, () => {
should(object[rule.notEndWith.property]).not.endWith(rule.notEndWith.value)
should(object[property]).not.endWith(value)
});
}
if (rule.maxLength) {
Expand All @@ -180,6 +189,6 @@ function lint(objectName, object, options = {}) {
}

module.exports = {
lint : lint,
loadRules : loadRules
lint,
loadRules
};

0 comments on commit d9a19ff

Please sign in to comment.