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

ESLint migration to v9 #414

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4807fc3
Bump the eslint group with 4 updates
dependabot[bot] Apr 22, 2024
f627cb5
some progress
Apr 22, 2024
70c0fce
solve errors
Sep 9, 2024
20c61d5
solve conflicts
Sep 9, 2024
800d1a0
install formats prettier
Sep 20, 2024
ac8cc42
v3.0.1-beta
Sep 20, 2024
210697f
solve conflicts
Sep 20, 2024
3905f2d
fix
Sep 20, 2024
7455a52
v3.0.1-beta-1
Sep 20, 2024
617a7b5
name all configs
Sep 20, 2024
3ab110b
v3.0.1-beta-2
Sep 20, 2024
8d280ed
fix jest config
Oct 4, 2024
1cdeb77
v3.0.1-beta-3
Oct 4, 2024
b34359e
fix again
Oct 4, 2024
d506175
v3.0.1-beta-4
Oct 4, 2024
d5bf2fb
v3.0.1-beta-5
Oct 4, 2024
dd89585
fix excluded file ts
Oct 4, 2024
cff76a0
v3.0.1-beta-6
Oct 4, 2024
1a63c33
migrate to ES Mmodules syntax
Oct 4, 2024
8e5f873
v3.0.1-beta-7
Oct 4, 2024
536325a
v3.0.1-beta-8
Oct 15, 2024
f5c83b3
ts configs
Oct 28, 2024
094c9aa
remove
Oct 28, 2024
694de07
refactor ts configs
Oct 28, 2024
c7cae3e
v3.0.1-beta-9
Oct 28, 2024
54ce43d
add logs
Nov 28, 2024
f2a455d
v3.0.1-beta-10
Nov 28, 2024
c2a784f
test
Nov 29, 2024
20f9e2c
v3.0.1-beta-11
Nov 29, 2024
051e247
another fix
Nov 29, 2024
ebf0128
v3.0.1-beta-12
Nov 29, 2024
f1c790b
another test
Nov 29, 2024
5f24769
v3.0.1-beta-13
Nov 29, 2024
afa2424
change import pluging
Dec 2, 2024
b91eea7
v3.0.1-beta-14
Dec 2, 2024
bdfe4d2
change import pluging
Dec 2, 2024
e946ec8
v3.0.1-beta-15
Dec 2, 2024
998d7a7
update readme
Dec 13, 2024
d9d4849
v3.0.1-beta-16
Dec 13, 2024
dc11ca4
resolve conflicts
Dec 13, 2024
e311088
add compatibility with common-js
Dec 17, 2024
1fc5cc4
v3.0.1-beta-17
Dec 17, 2024
d201a1e
fix
Dec 17, 2024
03c12e5
v3.0.1-beta-18
Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.js

This file was deleted.

178 changes: 45 additions & 133 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ yarn add --dev @cabify/eslint-config eslint prettier

## Usage

1. Create a `.eslintrc` file at the root of your project:
1. Create a `.eslint.config.js` file at the root of your project:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, review if we can define the config in a ts file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the eslint doc create an eslint.config.ts is an experimental feature.
In my opinion, we should keep the files as .js until we can configure without experimental options.

ref1


```json
{
"extends": ["@cabify/eslint-config/recommended"],
"rules": {
// Additional, per-project rules...
}
}
```js
import recommended from '@cabify/eslint-config';
/* Define an object for local configuration.
/ You can add your custom configuration and override existing rules here before exporting it.
const localConfig = {};
export default [...recommended, localConfig];
*/
export default [...recommended];
```

2. Add the lint task into your `package.json`:
Expand All @@ -41,15 +42,29 @@ yarn add --dev @cabify/eslint-config eslint prettier
...
"scripts": {
...
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:fix": "eslint ./ --fix",
"lint": "eslint ./",
...
}
```

3. Add a `.eslintignore` file to avoid checking unwanted files:
3. Add a `.globalIgnores` in your `eslint.config.js` to avoid checking unwanted files:

https://eslint.org/docs/user-guide/configuring/ignoring-code#the-eslintignore-file
```js
// https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
const globalIgnores = {
ignores: [
'dist',
'node_modules/*',
'storybook-static/*',
'test/*',
'build',
'scripts',
'webpack',
],
};
export default [...recommended, globalIgnores];
```

### Formatting

Expand All @@ -66,67 +81,27 @@ To format the files from your app a and checking them are properly formatted you
}
```

### Setup for Babel

If you use non-standard features in your JS code (like decorators),
or custom configs to import files you'll need to use `babel-eslint` as parser.
To do so, install the following dependencies and modify your `.eslintrc` file accordingly:

```sh
yarn add --dev babel-eslint eslint-import-resolver-babel-module
```

or

```sh
yarn add --dev babel-eslint eslint-import-resolver-babel-module
```

Modify `.eslintrc`:

```json
{
...
"parser": "babel-eslint",
"settings": {
...
"import/resolver": {
"babel-module": {}
}
}
}
```

### Setup for TypeScript

1. Install the following dependencies:

```sh
npm i -D eslint-import-resolver-typescript
```

or

```sh
yarn add --dev eslint-import-resolver-typescript
```

2. Modify `.eslintrc`:

```json
{
...
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json"
```js
const localConfigs = {
languageOptions: {
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2020,
},
},
"settings": {
...
"import/resolver": {
"typescript": {}
}
}
}
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
project: '<root>/tsconfig.json',
},
},
},
};

export default [...recommended, localConfigs];
```

3. Add a `./tsconfig.eslint.json` to the root of your project.
Expand Down Expand Up @@ -165,69 +140,6 @@ some rules. If you can live without them, just make these changes in your `.esli
}
```

### Setup for Jest

If you use Jest, installing its import resolver into your project is encouraged.

1. Install the following dependencies:

```sh
npm i -D eslint-import-resolver-jest
```

or

```sh
yarn add --dev eslint-import-resolver-jest
```

2. Modify `.eslintrc`:

```json
{
...
"settings": {
...
"import/resolver": {
...
"jest": {
"jestConfigFile": "./jest.config.js"
}
}
}
}
```

If you want to ensure that this resolver only applies to your test files, you can use ESLint's overrides configuration option:

```json
"overrides": [
{
"files": ["**/__tests__/**/*.js"],
"settings": {
"import/resolver": {
"jest": {
"jestConfigFile": "./jest.config.js"
}
}
}
}
]
```

3. Make sure that you have set up your jest config file (e.g., `./jest.config.js` )

## Legacy

If you want to maintain the formatting within ESLint, you can opt to extend the `@cabify/eslint-config/legacy` configuration instead of `@cabify/eslint-config/recommended`:

```json
{
"extends": ["@cabify/eslint-config/legacy"],
...
}
```

### Publish a new version

- Update [CHANGELOG](./CHANGELOG.md) with new features, breaking changes, etc
Expand Down
52 changes: 0 additions & 52 deletions configs/base.js

This file was deleted.

65 changes: 65 additions & 0 deletions configs/commonjs/base.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const globals = require('globals');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you use an ESmodule file for this?

It question applies to all configuration files.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see there are config files in ESmodule as well.

I don't understand why we need to define the config in both formats 🤷

const { isPackageAvailable } = require('./utils.cjs');
const bestPractices = require('./best-practices.cjs');
const errors = require('./errors.cjs');
const es6 = require('./es6.cjs');
const formats = require('./formats.cjs');
const imports = require('./imports.cjs');
const jest = require('./jest.cjs');
const lodash = require('./lodash.cjs');
const node = require('./node.cjs');
const postcss = require('./postcss.cjs');
const promises = require('./promises.cjs');
const react = require('./react.cjs');
const reactA11y = require('./react-a11y.cjs');
const storybook = require('./storybook.cjs');
const strict = require('./strict.cjs');
const style = require('./style.cjs');
const variables = require('./variables.cjs');

const isTSAvailable = isPackageAvailable('typescript');
let tsConfigs = [];
if (isTSAvailable) {
// eslint-disable-next-line global-require
const { tsLintConfig } = require('./ts.cjs');
tsConfigs = tsLintConfig;
}
const isJestAvailable = isPackageAvailable('jest');

const configs = [
bestPractices,
errors,
es6,
...imports,
node,
promises,
strict,
style,
variables,
react,
lodash,
reactA11y,
formats,
storybook,
postcss,
isJestAvailable && jest,
].filter(Boolean);

module.exports = [
...configs,
{
name: 'base-cabify-eslint-config',
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
},
},
rules: {
strict: 'error',
},
},
...tsConfigs,
];
Loading
Loading