-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
Handle deprecated rules #112
Comments
Hi! There used to be no deprecated rules included in this config, but then they were added after #8 was filed. |
@lydell Yeah, I've read it. Can you share your thoughts on the use case I've mentioned of validating user configured rules don't use deprecated ones? Maybe we can add them conditionally based on the version of ESLint the user is using? |
One idea I have is to move them to a separate, opt-in file. So if you need it, you can do: {
"extends": [
"prettier",
"prettier/legacy",
"prettier/react",
"prettier/react-legacy"
]
} I wonder who needs the legacy rules to be turned off. Is it advanced users with a legacy code base? Then it might be fine to split. Is it beginners? Then they might be confused. But on the other hand – wouldn’t beginners start out with new stuff? I wonder what configs still include those legacy rules. Another thought – could the eslint-find-rules tool be smarter about this somehow maybe? Perhaps it could ignore deprecated rules that come from third-party configs. Or maybe it could ignore deprecated rules that are set to Not sure what the best solution is yet. Do you have any more ideas?
I don’t think that’s possible in a config package. Just thought of a possible workaround. Instead of extending {
"extends": ["./prettier-workaround"]
} And define prettier-workaround.js like so: const prettierConfig = require("eslint-config-prettier");
const { "no-spaced-func": _1, "indent-legacy": _2, ...rules } = prettierConfig.rules;
module.exports = {
rules,
}; |
@lydell Thanks for giving it some attention :-).
e.g. const path = require('path');
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
const packageJson = require(packageJsonPath);
|
I somehow forgot that the configs exported from this package are JS files! So your idea of running some code before setting |
Working on a POC, works for now. |
@alexilyaev I just had an idea – we could look for a certain environment variable. If it’s set, don’t include deprecated rules. What do you think about that?
|
Hmm, that's an option, but requires an extra step from the user of I already have a working POC, it does the following...
Looks something like this: module.exports = {
rules: {
...
"generator-star-spacing": "off",
"implicit-arrow-linebreak": "off",
"indent": "off",
+ ...conditionalRule(semver.lt(eslintVersion, "4.0.0"), {
+ "indent-legacy": "off"
+ }),
"jsx-quotes": "off",
"key-spacing": "off",
...
}
} There are other ways to do this, but less clean. We depend on |
I think your solution sounds nice, but maybe a little overkill? I’m also worried that this will cause issues for people since resolving packages is always harder than you first thought, in my experience. |
Another idea: Maybe way too hacky, but maybe we could look att |
Not sure what that means... Here's how I'm doing it, adding const path = require("path");
const readPkg = require("read-pkg");
module.exports = moduleName => {
let modulePkg = null;
try {
modulePkg = readPkg.sync({
normalize: false,
cwd: path.resolve(process.cwd(), "node_modules", moduleName)
});
} catch (error) {
// Ignore the error if failed
}
return modulePkg;
}; And then outside... const readModulePkg = require("./lib/read-module-pkg");
const eslintDepPkg = readModulePkg("eslint");
const eslintVersion = eslintDepPkg && eslintDepPkg.version; |
|
Let me PR soon and we'll talk. |
My initial solution didn't cut it #120 (comment) |
Released in v6.5.0. Thanks for your help! |
prettier
:no-spaced-func
deprecated ineslint
since version3.3.0
indent-legacy
is deprecated ineslint
since version4.0.0
prettier/react
:react/jsx-space-before-closing
deprecated ineslint-plugin-react
since version7.0.0
:Not sure what's the policy here for deprecated rules.
My use case is to catch deprecated rules in an existing config using eslint-find-rules.
The issue is that projects have configurations with deprecated rules and ESLint does not warn about it.
So I'd like to catch such cases, possible with:
Ideally this would exit with a
0
value and when I bump ESLint or related configs/plugins, it'll exit with non0
and show me which rules are deprecated.Right now it's not possible when extending
eslint-config-prettier
:.eslintrc:
The text was updated successfully, but these errors were encountered: