Skip to content

Commit

Permalink
build: migrate eslint config to flat style (#913)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above
(following the Conventional Commits standard) -->
<!-- More infos: https://www.conventionalcommits.org -->
<!-- Commit types:
https://github.com/insurgent-lab/conventional-changelog-preset#commit-types-->

## Description

<!--- Describe your changes in detail -->
Migrate .eslintrc to esling.config.mjs. Using .mjs so I can use `import`
(.ts configs are still experimental). Fixed a few lint issues that were
easy, changed one new lint rule to a warn since it wasn't caught before.

## Related Issue

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

Fixes #899 

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
Using the new flat config for Eslint is required for upgrading to 9.0

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
Ran `npm run lint` and VS Code Eslint plugin many times

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] If my change introduces a breaking change, I have added a `!`
after the type/scope in the title (see the Conventional Commits
standard).
  • Loading branch information
intcreator authored Nov 12, 2024
1 parent 15bb206 commit 38c1044
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 75 deletions.
60 changes: 0 additions & 60 deletions .eslintrc

This file was deleted.

103 changes: 103 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import tseslint from 'typescript-eslint';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import jest from 'eslint-plugin-jest';
import js from '@eslint/js';

export default [
// using .mjs for module support as TypeScript Eslint configs are still experimental
{
name: 'Eslint config file',
files: ['eslint.config.mjs'],
// ...tseslint.configs.disableTypeChecked,
// ...js.configs.recommended,

languageOptions: {
sourceType: 'module',
parserOptions: {
// project: 'package.json'
}
}
},

{
name: 'general project rules',
files: ['**/*.ts'],

plugins: {
'@typescript-eslint': tseslint.plugin
},

languageOptions: {
globals: {
...globals.node
},

parser: tsParser,
ecmaVersion: 5,
sourceType: 'module',

parserOptions: {
project: 'tsconfig.json'
}
},

rules: {
// contains all of recommended, recommended-type-checked, and strict
...tseslint.configs.strictTypeChecked.rules,
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_'
}
],

'@typescript-eslint/naming-convention': [
'warn',
{
selector: ['typeLike'],
format: ['PascalCase']
},
{
selector: ['variableLike', 'function'],
format: ['camelCase'],
leadingUnderscore: 'allow'
},
{
selector: ['variable'],
format: ['camelCase', 'UPPER_CASE']
},
{
selector: 'variable',
types: ['boolean'],
format: ['PascalCase'],
prefix: ['is', 'should', 'has', 'can', 'did', 'was', 'will']
}
],
// this is set to warn because it wasn't caught before the eslint migration in 11/2024
'@typescript-eslint/restrict-template-expressions': 'warn'
}
},

{
name: 'test rules',
files: ['tests/**/*.ts'],

...jest.configs['flat/recommended'],
...jest.configs['flat/style'],

plugins: {
jest
},

rules: {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/unbound-method': 'off',
'jest/no-done-callback': 'off'
}
},

// Prettier plugin which should be last
eslintPluginPrettierRecommended
];
Loading

0 comments on commit 38c1044

Please sign in to comment.