-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix: deep copy standardRules config #316
fix: deep copy standardRules config #316
Conversation
Awesome! Thank you for finding the underlying cause of the issue, this is hilarious 😁 What do you think about this approach for fixing it instead though: diff --git a/src/index.ts b/src/index.ts
index a6254b5..05faf51 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -26,6 +26,10 @@ function fromEntries<T> (iterable: Array<[string, T]>): { [key: string]: T } {
}, {})
}
+function clone<T extends object | string | number | boolean | null> (value: T): T {
+ return JSON.parse(JSON.stringify(value))
+}
+
export = {
extends: 'eslint-config-standard',
plugins: ['@typescript-eslint'],
@@ -44,7 +48,7 @@ export = {
'no-use-before-define': 'off',
// @typescript-eslint versions of Standard.js rules:
- ...fromEntries(equivalents.map((name) => [`@typescript-eslint/${name}`, standardRules[name]])),
+ ...fromEntries(equivalents.map((name) => [`@typescript-eslint/${name}`, clone(standardRules[name])])),
'@typescript-eslint/no-use-before-define': ['error', {
functions: false,
classes: false, The benefits are:
sidebar: |
Also just thought about that. I updated the commit 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR, @Patrick-Remy. I would like to merge this fix, but:
- There are some extraneous files included.
- I would like the pull request to introduce a test that prevents this from regressing.
This fixes #303 invalid configuration for dot-notation
Yes, sorry for the history files. I added an extensive test for it 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the test, @Patrick-Remy. It covers what I am concerned about, but I feel it covers too much and is slightly more complex than I feel comfortable with. I'd like to ask you to make the following changes, if you don't mind.
src/index.test.ts
Outdated
|
||
test('No references in rules config', (t) => { | ||
for (const override of exported.overrides) { | ||
const rules: RulesConfig = override.rules |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this type, then, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required due to Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
if use standardRules[ruleName]
.
I think the tests are both required. The iteration is required, as the error can occur, if there are any references, also from different keys. You can reproduce it by following these steps:
{
"dependencies": {
"@types/node": "^14.0.5",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"eslint": "^7.1.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"typescript": "^3.9.3"
}
} this {
"compilerOptions": {
"target": "es2018",
"baseUrl": "src",
"outDir": "lib",
"module": "commonjs"
},
"include": [
"src"
]
} and this const eslintrc_json_1 = require("eslint-config-standard/eslintrc.json");
module.exports = {
extends: 'eslint-config-standard',
plugins: ['@typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
rules: {
'@typescript-eslint/dot-notation': eslintrc_json_1.rules['arrow-spacing']
}
}
]
}
allowKeywords: {
type: 'boolean',
default: true,
},
allowPattern: {
type: 'string',
default: '',
} to the
So References inbetween the override could also be problematic. Just imagine my personal config extends const config = require('eslint-config-standard-with-typescript')
config.overrides[0].rules['some-rule'] = ['error', {
custom: false
}]
module.exports = config If this lib would use the same config object for 'some-rule' and 'some-different-rule', this will result in unexpectedly modifying both of them. So it would be a bad style to use references inside the config. Hope you can get my points. |
@Patrick-Remy the only reuse-of-rule-by-reference we have is same-key from eslint-config-standard. That is removed in this PR and that is the only thing that should be tested against in this PR. More comprehensive testing is not worth the slightly increased complexity of the test, because there is no reasonable expectation that what it covers will ever be actually hit. Please do make those changes so that we could make a release. |
In my opinion tests should not use knowledge about the implementation details, to only cover that problems never reoccur in a specific case. The test now isn't preventing the root cause in a general way any more. It also hadn't any big performance downsides and it's now possible to pass the test, but run into this error again in a different case. But possibly that's only about philosophy. However, I also think a fast release is important now, as the package is broken for the most. If there are any changes required, please let me now. |
Thank you, @Patrick-Remy 💙 |
This fixes #303 invalid configuration for dot-notation
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x ] Bug fix
[ ] New feature
[ ] Other, please explain:
What changes did you make? (Give an overview)
Instead of assigning the equivalents config object, the must be deep copied
Which issue (if any) does this pull request address?
Addresses #303
Is there anything you'd like reviewers to focus on?
more elegant way for
[...val] as unknown as T