Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1436 #1623

Merged
merged 3 commits into from
Nov 1, 2017
Merged

fixes #1436 #1623

merged 3 commits into from
Nov 1, 2017

Conversation

hameleonka
Copy link
Contributor

introduces new cli param disable-linter-rules which accepts coma separated list of rules to be disabled

@EnTeQuAk EnTeQuAk self-requested a review October 27, 2017 11:32
Copy link
Contributor

@EnTeQuAk EnTeQuAk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, see my comments inline.

src/cli.js Outdated
@@ -81,6 +81,12 @@ export function getConfig({ useCLI = true } = {}) {
type: 'string',
requiresArg: true,
})
.option('disable-linter-rules', {
alias: ['dlr'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need an alias for this since that option will probably used by our scripts in addons-server 99,9% of the time.

src/cli.js Outdated
@@ -81,6 +81,12 @@ export function getConfig({ useCLI = true } = {}) {
type: 'string',
requiresArg: true,
})
.option('disable-linter-rules', {
alias: ['dlr'],
describe: 'Disable list of coma separated eslint rules',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a comma instead of a coma

src/linter.js Outdated
@@ -368,6 +368,8 @@ export default class Linter {
// TODO: Bring this in line with other scanners, see:
// https://github.com/mozilla/addons-linter/issues/895
collector: this.collector,
// list of disbled rules for js scanner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"list of disabled rules"

@@ -55,7 +74,7 @@ export default class JavaScriptScanner {
parserOptions: {
ecmaVersion: 2017,
},
rules: _ruleMapping,
rules: ruleMappingWithExclusion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why explicitly create a new object for that? Imho _ruleMapping should still work for this right? We essentially just want to avoid to defineRule for disabled rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct, my mistake, sorry

@@ -40,6 +57,8 @@ export default class JavaScriptScanner {
_ruleMapping = ESLINT_RULE_MAPPING,
_messages = messages,
} = {}) {
const ruleMappingWithExclusion = excludeRules(_ruleMapping, this.disabledRules);
const rulesAfterExclusion = excludeRules(_rules, this.disabledRules);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could reduce the complexity of that code a bit by just using forEach with a delete inside:

import cloneDeep from 'lodash.clonedeep';

const enabledRules = cloneDeep(_rules);
this._disabledRules.forEach((key) => { delete enabledRules[key] });

I think that could work (untested though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this._disabledRules - is object not an array

...result,
[i.trim()]: true,
};
}, {}) : {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a simple map (given that disabledRules can be an array instead of an object, see comment down below) would work easier here.

this.disabledRules = typeof options.disabledRules === 'string' ? options.disabledRules.split(',')
    .map(rule => { rule.trim() })
    .filter(() => { return true; });

map cleans the strings and filter filters out empty elements by default so the result should be similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not the same in my case we have map

{ 
  rule0: true,
  rule1: true,
}

in your case we have array of rules. it just faster to look in the object if it has property, than lookup in the array if it has item, if you want I can change it to array

expect(typeof jsScanner.disabledRules).toEqual('object');
// This test assures us the disabledRules can be accessed like an object.
expect(typeof jsScanner.disabledRules.someUndefinedProp).toEqual('undefined');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that test should be more something like

it('should have no rules disabled by default', () => {
    const jsScanner = new JavaScriptScanner('', 'filename.txt');
    expect(jsScanner.disabledRules).ToEqual({}); // or [] given my comments above
});

That way you can merge those two checks into one.

expect(typeof jsScanner.disabledRules).toEqual('object');
// This test assures us the disabledRules built properly.
expect(jsScanner.disabledRules['no-unsafe-innerhtml/no-unsafe-innerhtml']).toBe(true);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I would compare the actual expected disabledRule object.

});
expect(typeof jsScanner.disabledRules).toEqual('object');
expect(jsScanner.disabledRules).toEqual({});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, here you did the check correctly. I don't think you need the typeof check though.

'no-unsafe-innerhtml/no-unsafe-innerhtml': true,
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's precisely what I meant 👍

Copy link
Contributor

@EnTeQuAk EnTeQuAk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect now, thanks a lot for the updates!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants