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

feat: Avoid dirname for built-in configs #70

Closed
wants to merge 6 commits into from

Conversation

daidodo
Copy link
Contributor

@daidodo daidodo commented Feb 13, 2022

Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575

Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 13, 2022

CLA Not Signed

@eslint-github-bot eslint-github-bot bot added the bug Something isn't working label Feb 13, 2022
Comment on lines 221 to 227
eslintRecommendedPath,
eslintAllPath
eslintRecommendedConfig,
eslintAllConfig
Copy link
Member

Choose a reason for hiding this comment

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

I marked this PR as "breaking" (and we'll have to update the commit tag) because this change is backward-incompatible, so we'd need to bump @eslint/eslintrc to 2.0 to avoid using it from ESLint v8.0.0-v8.9.0.

Copy link
Member

Choose a reason for hiding this comment

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

As an alternative, we could keep these string options, add new ones for objects, and support both paths and objects (if the objects are passed in, then use them; otherwise, use paths). That wouldn't be a breaking change for this package. Though it would make the code a bit more complicated, and I'm not sure if anyone other than eslint/eslint is using this API.

@nzakas thoughts about this, should we keep the existing API and just add new options?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don’t want to make any breaking changes at this point. It probably makes sense to just add new properties and throw an error if both a path and an object are passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments!

I've updated the code to keep the compatibility.

Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
@mdjermanovic
Copy link
Member

@daidodo can you please sign CLA, so we could merge the PRs when they're ready?

Note that your email associated with the commits on these PRs is not the same as the one associated with your GitHub user account.

Comment on lines -228 to +226
eslintAllPath: path.resolve(dirname, "../conf/eslint-all.cjs"),
eslintRecommendedPath: path.resolve(dirname, "../conf/eslint-recommended.cjs")
getEslintAllConfig: () => ({ settings: { "eslint:all": true } }),
getEslintRecommendedConfig: () => ({ settings: { "eslint:recommended": true } })
Copy link
Member

Choose a reason for hiding this comment

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

👍

Can you also delete those two .cjs files, as they are no longer used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mdjermanovic mdjermanovic changed the title fix: Avoid dirname for built-in configs. feat: Avoid dirname for built-in configs Feb 16, 2022
@mdjermanovic mdjermanovic removed bug Something isn't working breaking labels Feb 16, 2022
@mdjermanovic
Copy link
Member

I marked this as feat:, because it adds new options to public API.

Comment on lines 45 to 60
/**
* Return config data for built-in eslint:all.
* @returns {ConfigData} Config data
*/
function getEslintAllConfig() {
return import("../fixtures/eslint-all.cjs");
}

/**
* Return config data for built-in eslint:recommended.
* @returns {ConfigData} Config data
*/
function getEslintRecommendedConfig() {
return import("../fixtures/eslint-recommended.cjs");
}

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work as expected, because import() returns a Promise. We can probably use require() here (require is created on line 24).

I believe that's the reason why one test is failing:

635 passing (2s)
  1 failing

  1) ConfigArrayFactory
       '_normalizeConfigData(configData, ctx)' method should normalize the config data.
         'extends' details
           if 'extends' property was 'eslint:all', the returned value
             should have the config data of 'eslint:all' at the first element.:

      AssertionError: expected { type: 'config', …(15) } to deeply equal { …(16) }
      + expected - actual

       {
         "criteria": [null]
         "env": [undefined]
      -  "filePath": ""
      +  "filePath": "/home/runner/work/eslintrc/eslintrc/tests/fixtures/eslint-all.cjs"
         "globals": [undefined]
         "ignorePattern": [undefined]
         "name": ".eslintrc » eslint:all"
         "noInlineConfig": [undefined]
--
         "plugins": [undefined]
         "processor": [undefined]
         "reportUnusedDisableDirectives": [undefined]
         "root": [undefined]
      -  "rules": [undefined]
      +  "rules": {
      +    "curly": [
      +      "error"
      +    ]
      +    "eqeqeq": [
      +      "error"
      +    ]
      +  }
         "settings": [undefined]
         "type": "config"
       }
      
      at assertConfigArrayElement (file:///home/runner/work/eslintrc/eslintrc/tests/lib/config-array-factory.js:[88](https://github.com/eslint/eslintrc/runs/5220072307?check_suite_focus=true#step:5:88):12)
      at Context.<anonymous> (file:///home/runner/work/eslintrc/eslintrc/tests/lib/config-array-factory.js:[104](https://github.com/eslint/eslintrc/runs/5220072307?check_suite_focus=true#step:5:104)4:21)

You can run npm test locally to check.

What's surprising is that only one test is failing. Can we, instead of semi-randomly mixing strings and functions in tests, convert all tests to use the new functions getEslintAllConfig and getEslintRecommendedConfig, and then duplicate tests that have eslint:all and eslint:recommended to check if they work with eslintAllPath and eslintRecommendedPath, for backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for missing the failed tests. Will fix it.

zddai and others added 2 commits February 16, 2022 21:41
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint/eslint#15575
@daidodo
Copy link
Contributor Author

daidodo commented Feb 16, 2022

Sorry, the git accounts have been a mess on my laptop.
I've created new PRs (#71 and eslint/eslint#15616) to address the comments and with clean commit histories.

Closing eslint/eslint#15602 and this PR.

@daidodo daidodo closed this Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: ESLint API cannot find eslint-recommended.js
4 participants