Skip to content

Rule Blocklist #231

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

Merged
merged 2 commits into from
Apr 5, 2017
Merged

Rule Blocklist #231

merged 2 commits into from
Apr 5, 2017

Conversation

pointlessone
Copy link
Contributor

Add a way to disable rules.

One particular case is #222.

@@ -7,6 +7,7 @@ const ConfigFile = require("eslint/lib/config/config-file");

const Config = require("eslint/lib/config");
const ConfigUpgrader = require("./config_upgrader");
const RuleBlacklist = require("./rule_blacklist");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you rename your files and variables to use "blocklist" throughout?

@pointlessone pointlessone changed the title Rule Blacklist Rule Blocklist Mar 22, 2017
let report = [];

for (const name in blocklistedRules) {
if (Reflect.has(rules, name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what's Reflect? I don't see it being required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"use strict";

const
CONFIG_FILES = require("eslint/lib/config/config-file").CONFIG_FILES
Copy link
Contributor

Choose a reason for hiding this comment

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

💄 not sure what project style is, but elsewhere you put the first value on the line with const.

@@ -0,0 +1,84 @@
"use strict";

const a = "a"
Copy link
Contributor

Choose a reason for hiding this comment

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

What's a for?

@dblandin
Copy link
Contributor

This is looking good! The current rule configured in the blocklist is missing the import/ prefix, but after fixing that the engine successfully ignored the rule. 🎉

Instead of

Ignored rules:

* import/no-unresolved:
  Code Climate doesn't fetch your project's dependencies so this rule produces high amount of false positives.

what do you think of outputting a list of ignored rules (if any) after a brief explanation:

Ignoring the following rules that rely on module resolution:

* import/no-unresolved


const blocklistedRules = {
"no-unresolved": "Code Climate doesn't fetch your project's dependencies so this rule produces high amount of false positives."
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Mentioned in another comment but repeating here inline: I don't think we need to support separate explanations for blocklisted rules just yet. This can be an array of rules and we can provide an explanation after updating the config.

no-resolved should be import/no-resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignoring the following rules that rely on module resolution:

* import/no-unresolved

Right now we have just one reason (we know of) to turn off rules. And we have just one rule (I didn't do extensive research on this yet). It's an appropriate way to format the message for it.

However, it doesn't seem to be the only possible reason. I specifically chosen this approach because there might be others and it will be a bit easier to change it in the future — just add it to this object, no code changes needed.

Here are a few examples of other reasons we may want to disable a rule I can think of:

  • A platform-specific rule that is incompatible with Linux
  • A rule that relies on an external tool that is not in the container
  • A rule that tries to use network
  • A rule that is incompatible with Node version we run

I'm not opposing the proposed change. I'm just presenting my reasoning behind the design. I'll make the change if you prefer it.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should definitely audit all rules currently available via our vendored plugins and add any that rely on module resolution to this blocklist either in this PR or the next one.

Here's one example of another rule that should be in the blocklist:
import/extensions
https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/extensions.js

Here are a few examples of other reasons we may want to disable a rule I can think of

Until we actually want to ignore rules for another reason, I'd stick with a simpler implementation that doesn't map particular rules to warning messages. I don't think it's worth adding now. If we need it later, we can add it then.

@dblandin
Copy link
Contributor

@pointlessone Anything I can do to help push this along?

@efueger
Copy link
Member

efueger commented Apr 3, 2017

Another rule that should probably be included in the blocklist:

Otherwise, repos see issues like: "Resolve error: unable to load resolver "babel-module"."

@dblandin
Copy link
Contributor

dblandin commented Apr 4, 2017

@pointlessone Looks like a good portion of the diff is refactoring the config finder. Would you mind splitting that refactor into a separate commit so the rule blocklist additions can stand alone?

@dblandin
Copy link
Contributor

dblandin commented Apr 4, 2017

@pointlessone Have you been able to audit the currently vendored plugins for other rules that rely on module resolution? It would be great if we could catch and blocklist any others.

@pointlessone
Copy link
Contributor Author

@dblandin No, I haven't audited other rules. It's a rather time consuming task. I'm not sure if that's an effective use of time. I thought we could push this and add more rules as we hit more false positives. /cc @gordondiggs

TBH, I'm not sure about import/extensions rule either. According to docs it seem only deal with extensions and shouldn't rely on module resolution. On the other hand, implementation seem to use resolve. ¯\_(ツ)_/¯

@dblandin
Copy link
Contributor

dblandin commented Apr 4, 2017

I'm fine rolling with this if you think an audit is too time intensive right right now.

I was thinking of a simple ack/grep for rules calling out to resolve and checking each briefly for module resolution:

$ ack "resolve" ./**/rules/**/*.js | grep ".js$"

eslint-config-airbnb-base/rules/imports.js
eslint-config-airbnb-base/rules/style.js
eslint-config-airbnb/rules/react.js
eslint-config-simplifield/node_modules/eslint-plugin-angular/rules/deferred.js
eslint/lib/rules/global-require.js
eslint/lib/rules/no-alert.js
eslint/lib/rules/no-loop-func.js
eslint/lib/rules/no-path-concat.js
eslint/lib/rules/no-unmodified-loop-condition.js
eslint/lib/rules/no-unused-vars.js
eslint/lib/rules/no-use-before-define.js
eslint/lib/rules/prefer-const.js
eslint/lib/rules/prefer-promise-reject-errors.js
eslint-plugin-angular/rules/deferred.js
eslint-plugin-filenames/lib/rules/match-exported.js
eslint-plugin-filenames/lib/rules/match-regex.js
eslint-plugin-filenames/lib/rules/no-index.js
eslint-plugin-flowtype/dist/rules/defineFlowType.js
eslint-plugin-import/lib/rules/extensions.js
eslint-plugin-import/lib/rules/no-duplicates.js
eslint-plugin-import/lib/rules/no-internal-modules.js
eslint-plugin-import/lib/rules/no-restricted-paths.js
eslint-plugin-import/lib/rules/no-unresolved.js
eslint-plugin-inferno/lib/rules/no-unused-prop-types.js
eslint-plugin-inferno/lib/rules/prop-types.js
eslint-plugin-jsx-a11y/lib/rules/aria-proptypes.js
eslint-plugin-jsx-a11y/src/rules/aria-proptypes.js
eslint-plugin-node/lib/rules/no-hide-core-modules.js
eslint-plugin-node/lib/rules/no-unpublished-bin.js
eslint-plugin-node/lib/rules/shebang.js
eslint-plugin-promise/rules/lib/is-promise.js
eslint-plugin-promise/rules/no-return-wrap.js
eslint-plugin-promise/rules/param-names.js
eslint-plugin-react/lib/rules/no-unused-prop-types.js
eslint-plugin-react/lib/rules/prop-types.js
eslint-plugin-react/lib/rules/require-default-props.js

@pointlessone
Copy link
Contributor Author

@dblandin Split the commits.

Simple grep is a rather naive approach. I imagine it can hit all sorts of unrelated things: comments, any function/var that has this rather generic term in them, etc.

Moreover, not every resolve is destined to hit external modules. After all there's some code in the project.

Let's merge this PR as is (or with the changes directly related to it) and expand the list of blocked rules in a separate PR. I'll go through the list you posted and add rules if they primarily deal with external modules. Otherwise, users can mark false-positives.

@dblandin
Copy link
Contributor

dblandin commented Apr 5, 2017

Sounds good!

@pointlessone pointlessone merged commit 7c0ac0a into master Apr 5, 2017
@pointlessone pointlessone deleted the rule-blacklist branch April 5, 2017 13:48
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.

5 participants