Skip to content

Missing extends in generated config #232

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

Closed
jeremyyap opened this issue Oct 8, 2019 · 6 comments · Fixed by #245
Closed

Missing extends in generated config #232

jeremyyap opened this issue Oct 8, 2019 · 6 comments · Fixed by #245
Assignees
Labels
status: accepting prs Please, send in a PR to resolve this! ✨ type: bug Something isn't working

Comments

@jeremyyap
Copy link
Contributor

🐛 Bug Report

  • tslint-to-eslint-config version: 0.2.7
  • ESLint version: 6.5.1
  • Node version: 12.10.0

Actual Behavior

extends is an empty array in the output even if there were extends in the original .eslintrc

Expected Behavior

The extends in the original .eslintrc should be retained

Reproduction

Original .eslintrc.js:

module.exports = {
  extends: ["airbnb"]
}

Output using ESLint 5:

module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        ".../node_modules/eslint-config-airbnb-base/rules/best-practices.js",
        ".../node_modules/eslint-config-airbnb-base/rules/errors.js",
        ".../node_modules/eslint-config-airbnb-base/rules/node.js",
        ".../node_modules/eslint-config-airbnb-base/rules/style.js",
        ".../node_modules/eslint-config-airbnb-base/rules/variables.js",
        ".../node_modules/eslint-config-airbnb-base/rules/es6.js",
        ".../node_modules/eslint-config-airbnb-base/rules/imports.js",
        ".../node_modules/eslint-config-airbnb-base/rules/strict.js",
        ".../node_modules/eslint-config-airbnb-base/index.js",
        ".../node_modules/eslint-config-airbnb/rules/react.js",
        ".../node_modules/eslint-config-airbnb/rules/react-a11y.js",
        "airbnb"
    ],
    ...
};

Output using ESLint 6:

module.exports = {
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [],
    ...
};

It seems that the behaviour of the --print-config flag changed in ESLint 6 and it no longer prints extends

@JoshuaKGoldberg JoshuaKGoldberg added hacktoberfest status: needs investigation Let's dig deeper into this before drawing conclusions. type: bug Something isn't working and removed hacktoberfest labels Oct 10, 2019
@JoshuaKGoldberg
Copy link
Member

Well that's unfortunate 😞. The TSLint behavior equivalent is also mentioned here: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md

Is there some way to figure out the extends logic, maybe...?

@jeremyyap
Copy link
Contributor Author

I dug into this and came up with a working solution: jeremyyap@67c0b15

Admittedly it's quite a hacky solution but this is the only one I found so far besides just copying over the file parsing code from ESLint. I needed to use rewire as the functionality we need is not exposed by ESLint, not even exported by the file it's in.

https://github.com/eslint/eslint/blob/97045ae0805e6503887eef0b131dcb9e70b6d185/lib/cli-engine/config-array-factory.js#L248-L266

On the plus side though, this will also solve #58 😅

@jeremyyap
Copy link
Contributor Author

I think it might make more sense to copy ESLint's file parsing logic over. Then it could be used to parse TSLint and TS config files as well, and would help to solve #2, #4 and #151. The downside of that is that we would be parsing some files twice, once for the raw config and once for the normalized/flattened config, although performance should be less of a concern for a run-once script?

@JoshuaKGoldberg
Copy link
Member

Mmhh, rewire is a hacky solution, agreed. Though that is really nifty... 😄

My main concern would be taking a dependency on ESLint's lib/ directory structure. So let's avoid that if possible.

performance should be less of a concern for a run-once script,

Indeed, a few extra file parses -even for multi-level file parsings- shouldn't be an issue.

I think a quick solution for now would be to import the raw ESLint and TSLint configurations and add any 'raw' extends items there onto the 'reported' ones from the tools. That'll handle the common case of a single file that extends from some other packages. Later on we can replace that simple import with some fancier logic to handle the case of a file that extends a file that extends another file.

The one tricky thing there is that we can't import("json-file-with-comment.json"), so the importer function will have to accommodate for that...

@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Oct 20, 2019
@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send in a PR to resolve this! ✨ and removed status: needs investigation Let's dig deeper into this before drawing conclusions. labels Oct 20, 2019
@JoshuaKGoldberg
Copy link
Member

#245 should start on that quick solution. 🚀

@JoshuaKGoldberg
Copy link
Member

@jeremyyap #245 is merged in now, but if you think there's a flaw in its logic or have a better solution, I'm all ears! We can either re-open this issue or file a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send in a PR to resolve this! ✨ type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants