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

Config json cloning is a BREAKING CHANGE! #13447

Closed
JounQin opened this issue Jun 28, 2020 · 14 comments · Fixed by #13449
Closed

Config json cloning is a BREAKING CHANGE! #13447

JounQin opened this issue Jun 28, 2020 · 14 comments · Fixed by #13449
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@JounQin
Copy link
Contributor

JounQin commented Jun 28, 2020

Related: #13034 (comment)

Tell us about your environment

  • ESLint Version: 7.3.1
  • Node Version: v14.4.0
  • npm Version: 6.14.4

What parser (default, Babel-ESLint, etc.) are you using?

eslint-mdx

Please show your full configuration:

Configuration
module.exports = {
  extends: 'plugin:unicorn/recommended',
  rules: {
    'unicorn/filename-case': [
      2,
      {
        cases: {
          kebabCase: true,
          pascalCase: true,
        },
        // ignore UPPER_CASE markdown filenames
        ignore: [/^[A-Z](([\dA-Z]+_)*[\dA-Z]+)?\.mdx?$/],
      },
    ]
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

<!-- README.md -->
eslint README.md

What did you expect to happen?
no error

What actually happened? Please include the actual, raw output from ESLint.

1:2  error  Filename is not in kebab case or pascal case. Rename it to `readme.md` or `Readme.md`  unicorn/filename-case

The error occurres because the ESLint config is json cloned since v7.3.0, and this breaks Regxp option of unicorn/filename-case, I don't think this is an invalid usage.

@JounQin JounQin added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jun 28, 2020
@anikethsaha
Copy link
Member

You can try regex in string ? in your case, '/^[A-Z](([\dA-Z]+_)*[\dA-Z]+)?\.mdx?$/', though the flags wont work here, there can be work-around in the unicorn plugin to remove the regex instance and go with full string , even string for flags in a array

like

ignore: [ '^FOOBAR\\.js$', ['^FOOBAR\\.js$', 'i'] ]

but yeah , this was a breaking change.

@aladdin-add aladdin-add added evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion patch candidate This issue may necessitate a patch release in the next few days rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jun 28, 2020
@aladdin-add
Copy link
Member

what do you think revert the change? we can reconsider introducing it in a major release(eslint v8)

@anikethsaha
Copy link
Member

I did mention that earlier, #13034 (comment).

+1 for that

@kaicataldo
Copy link
Member

I personally think this change should be reverted (even though I understand it was considered a bug fix, because the intention was always to have ESLint configs be serializable). @eslint/eslint-tsc I know there was other discussion of this while I was on vacation. Would someone like to fill us in on what the final decision was?

@nzakas
Copy link
Member

nzakas commented Jun 30, 2020

The discussion was to wait and see how many bug reports we received before deciding whether to revert or not. We had just one report of the use of Infinity, and given that was clearly a bug and could be easily replaced with a valid number to work the same, we decided to add a patch to allow that isolated case.

This case is more concerning because it involves encouraging end users to use regular expressions in their configs (vs one isolated instance of Infinity in one config).

With this new data, I’m in favor of reverting the change.

@aladdin-add
Copy link
Member

well, seems we have reached a consensus to revert it. will make a PR later!

@kaicataldo
Copy link
Member

@btmills @mysticatea Would love to hear your opinions as well :)

@mysticatea
Copy link
Member

👍 for reverting.

@btmills
Copy link
Member

btmills commented Jun 30, 2020

Agreed with @nzakas - this is the sort of end-user case we were looking for that would indicate we need to revert. A couple things we could do in addition to reverting:

  • Add custom replacer functions that log non-fatal warnings when non-serializable values are found in the cache and --print-config option.
  • Open an issue with eslint-plugin-unicorn to start a discussion around alternatives.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Jun 30, 2020

Note that the cloning isn't the issue; it's using JSON to clone that's the issue. A proper deep cloning algorithm would work fine and preserve the fix that cloning originally solved.

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jun 30, 2020
@kaicataldo
Copy link
Member

Marking as accepted since the entire TSC is in favor of reverting.

@kaicataldo
Copy link
Member

@ljharb Yeah, that was also explored. I believe the reason that implementation was not chosen was due to challenges with potential circular references.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Jun 30, 2020

@kaicataldo yeah, that gets tricky, but i'd expect that to be handleable with a WeakMap, and mapping "original object" to "cloned object", prior to iterating over the original object to clone copies into the cloned object, and always looking up a cloned object in the map before creating a new one.

@anikethsaha
Copy link
Member

similar to #13034 (comment) ?

@kaicataldo kaicataldo removed the patch candidate This issue may necessitate a patch release in the next few days label Jul 2, 2020
kaicataldo pushed a commit that referenced this issue Jul 3, 2020
* Revert "Fix: Replace Infinity with Number.MAX_SAFE_INTEGER (fixes #13427) (#13435)"

This reverts commit de77c11.

* Revert "Fix: clone config before validating (fixes #12592) (#13034)"

This reverts commit 7fb45cf.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 31, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants