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

Add util for creating extendable ESLint configurations #374

Merged
merged 6 commits into from
Sep 26, 2024

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Sep 25, 2024

typescript-eslint has a nice util function to create a config with an extends property, similar to the legacy ESLint configuration format. We don't use TypeScript in all projects however, and the function has some limitations. In this PR, I've created a similar function createConfig, which is exported from @metamask/eslint-config.

The function supports an extends property, which accepts:

  • A config object, i.e., { extends: configObjectA }.
  • A config array, i.e., { extends: [configObjectA, configObjectB] }.
  • A nested config array, i.e., { extends: [[configObjectA, configObjectB]] }.
    • This removes the need to spread the config array.

@Mrtenz Mrtenz force-pushed the mrtenz/config-utils branch from 4c8a1b8 to 0e669be Compare September 25, 2024 12:08
Base automatically changed from mrtenz/eslint-9 to main September 25, 2024 17:52
@Mrtenz Mrtenz force-pushed the mrtenz/config-utils branch from 9518969 to cb046f6 Compare September 26, 2024 09:04
// TODO: Use import attributes when ESLint supports them.
const customRequire = createRequire(import.meta.url);
const environmentRules = customRequire('./environment.json');

/**
* @type {import('eslint').Linter.Config[]}
*/
const rules = [
Copy link
Member Author

Choose a reason for hiding this comment

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

GitHub shows this as a lot of changes, but essentially it just wraps the entire config in createConfig. As you can tell by the rules snapshot, the actual config hasn't changed.

@Mrtenz Mrtenz marked this pull request as ready for review September 26, 2024 10:29
@Mrtenz Mrtenz requested review from a team as code owners September 26, 2024 10:29
cryptodev-2s
cryptodev-2s previously approved these changes Sep 26, 2024
@Mrtenz Mrtenz merged commit 3a4c482 into main Sep 26, 2024
13 checks passed
@Mrtenz Mrtenz deleted the mrtenz/config-utils branch September 26, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants