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!: Migrate to ESLint v9. #3

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0f2f6a0
Migrate to ESLint v9: only common; removed all deprecated rules by st…
junhaoliao Dec 28, 2024
dff69ba
add new rules since v9:
junhaoliao Dec 28, 2024
979d00c
@stylistic/js
junhaoliao Dec 28, 2024
0397f42
Remove `^@` group from `simple-import-sort/imports`.
junhaoliao Dec 28, 2024
8eca3d8
@stylistic/plus
junhaoliao Dec 28, 2024
ce6cf8d
Remove common.js and related config in package.json; Add eslint.confi…
junhaoliao Dec 28, 2024
490fc80
Migrate jest.js.
junhaoliao Dec 28, 2024
e0fac0e
Ensure two blank lines before export.
junhaoliao Dec 28, 2024
7c03a71
Avoid exposing `common` config.
junhaoliao Dec 28, 2024
d877f74
Remove redundant line.
junhaoliao Dec 28, 2024
ac0fe90
Remove `node` globals from common config.
junhaoliao Dec 28, 2024
b8dccee
Change import sorting rules.
junhaoliao Dec 28, 2024
b9bdc27
Migrate `react`;
junhaoliao Dec 28, 2024
762bed7
react plugin
junhaoliao Dec 28, 2024
91de045
Remove react.js.
junhaoliao Dec 28, 2024
87b8fd6
Fix indent.
junhaoliao Dec 28, 2024
0774e26
Migrate meteor config.
junhaoliao Dec 28, 2024
1d0d5a0
Migrate typescript config.
junhaoliao Dec 28, 2024
a5c5fb2
Fix bare object / file naming.
junhaoliao Dec 28, 2024
b819542
Fix import naming.
junhaoliao Dec 28, 2024
31f284c
Fix export naming.
junhaoliao Dec 28, 2024
fd12f8c
Extract Stylistic rules into a separate config, which also adds Styli…
junhaoliao Dec 28, 2024
d03e6fa
chore: Upgrade version for 1.0.0 release.
junhaoliao Dec 28, 2024
a97dc0e
Remove unnecessary spread operator in TsConfig import.
junhaoliao Dec 28, 2024
620bc8c
Move side effect group to the last of imports.
junhaoliao Dec 28, 2024
8f0edf6
Decouple.
junhaoliao Dec 28, 2024
de3be18
Sort.
junhaoliao Dec 28, 2024
6982ed7
Sort.
junhaoliao Dec 28, 2024
05d00d9
Add ts-specific options for @stylistic/comma-dangle.
junhaoliao Dec 28, 2024
01511c8
Removed deprecated allowMultiplePropertiesPerLine from @stylistic/obj…
junhaoliao Dec 28, 2024
24b5826
use array syntax for consistency
junhaoliao Dec 28, 2024
3602bf5
TS: Enable and configure `@stylistic/member-delimiter-style` rule
junhaoliao Dec 28, 2024
dc5e5c4
Simplify the "@stylistic/lines-around-comment" rule by removing unnec…
junhaoliao Dec 28, 2024
3ac267c
TS: add padding-line-between-statements ts-specific keywords.
junhaoliao Dec 28, 2024
473728e
TS: enforce semi for @stylistic/member-delimiter-style
junhaoliao Dec 28, 2024
ab5d839
Disallow block-spacing.
junhaoliao Dec 28, 2024
b576db8
The @stylistic/lines-around-comment options are necessary.
junhaoliao Dec 28, 2024
09dbd7f
MeteorConfig does not have to be in an array.
junhaoliao Dec 28, 2024
a1cd2f8
Update README.md.
junhaoliao Dec 28, 2024
bbc8d56
Add eslint-import-resolver-typescript to peerDependencies.
junhaoliao Dec 29, 2024
2f194d4
Add createTsConfigOverride function for custom TypeScript configs.
junhaoliao Dec 29, 2024
fb854cd
Add `createTsConfigOverride` helper to README examples.
junhaoliao Dec 29, 2024
6be95c8
Docs - Apply suggestions from code review
junhaoliao Jan 4, 2025
b343b20
Remove extraneous newlines.
junhaoliao Jan 4, 2025
68405ea
Remove License section from README.
junhaoliao Jan 4, 2025
ede36ed
Update package.json with metadata and licensing details.
junhaoliao Jan 4, 2025
8c7173a
Remove unused test script from package.json.
junhaoliao Jan 4, 2025
f3b3d6a
Improve expression on the TsConfigArray <- StylisticConfigArray order.
junhaoliao Jan 4, 2025
4a4a353
Add reference and rationale for react/jsx rule configuration.
junhaoliao Jan 4, 2025
42418b8
Reorder and clarify allowed TypeScript types in "@stylistic/lines-aro…
junhaoliao Jan 4, 2025
b66f68c
Clarify TsConfigArray function documentation.
junhaoliao Jan 4, 2025
7cb4644
Rename `project` to `projectConfigPath`; updated related docs.
junhaoliao Jan 4, 2025
3304e16
Update `simple-import-sort/imports` groups; Add examples for the impo…
junhaoliao Jan 4, 2025
fbe33ab
Disable `no-new-symbol` ESLint rule due to deprecation.
junhaoliao Jan 4, 2025
e4b747b
Fix line length violations.
junhaoliao Jan 4, 2025
39450ee
Remove deprecated `experimentalObjectRestSpread` parserOptions from C…
junhaoliao Jan 4, 2025
46ccf99
Add docs for deprecated rule "@stylistic/func-call-spacing".
junhaoliao Jan 4, 2025
d108e36
Improve expression: docs for deprecated rule "@stylistic/func-call-sp…
junhaoliao Jan 4, 2025
ce3266f
Use PascalCase naming for all default imports.
junhaoliao Jan 5, 2025
6aa2e0e
Update typescript-eslint to version 8.19.0
junhaoliao Jan 5, 2025
0a759ac
Fix line width violation - Apply suggestions from code review
junhaoliao Jan 6, 2025
6b59dcf
Docs - Apply suggestions from code review
junhaoliao Jan 6, 2025
a25917d
Use string concat instead to fix line width violation - Apply suggest…
junhaoliao Jan 6, 2025
c897715
Docs - Apply suggestions from code review
junhaoliao Jan 6, 2025
7d9ba94
createTsConfigOverride - Simplify and clarify the function descriptio…
junhaoliao Jan 6, 2025
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
447 changes: 447 additions & 0 deletions CommonConfig.mjs

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions jest.js → JestConfig.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module.exports = {
env: {
jest: true,
import globals from "globals";


const JestConfig = {
languageOptions: {
globals: {
...globals.jest,
},
},
rules: {
"no-magic-numbers": "off",

"jsdoc/check-tag-names": [
"warn",
{
Expand All @@ -12,3 +18,6 @@ module.exports = {
],
},
};


export default JestConfig;
23 changes: 23 additions & 0 deletions MeteorConfig.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import globals from "globals";


const MeteorConfig = {
languageOptions: {
globals: {
...globals.jest,
...globals.meteor,
...globals.node,
},
},
settings: {
"import/core-modules": [
"meteor/meteor",
"meteor/mongo",
"meteor/accounts-base",
"meteor/react-meteor-data",
],
},
};


export default MeteorConfig;
226 changes: 160 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# eslint-config-yscope

This repository contains ESLint configurations for various JavaScript environments under the `yscope` namespace. Our configurations are designed to enforce a consistent coding style and catch common bugs, making your codebase more maintainable and error-free.
This repository contains ESLint ["flat"][eslint-flat-config] configurations for various JavaScript
environments under the `yscope` namespace. Our configurations are designed to enforce a consistent
coding style and catch common bugs, making your codebase more maintainable and error-free.

## Installation

Expand All @@ -14,83 +16,175 @@ yarn add --dev eslint-config-yscope

### For Older Node.js Versions

If you are using `npm` version >= 3 or < 7, you need to install the `peerDependencies` specified in https://github.com/y-scope/eslint-config-yscope/blob/e0dc97bd6f738b06ee692bd52f0fceb6996c1625/package.json#L14-L26

Alternatively, you can upgrade your `npm` to the latest version compatible with your Node.js version.
- Node.js verions below v16: `npm i -g npm@9`
- Node.js v16 or above: `npm i -g npm@latest`
This package requires ESLint 9, which in turn requires Node.js 18 or above. If you are using an
older version of Node.js, you can use version `0.0.32` of this package, which is compatible with
ESLint 8. Detailed setup instructions for this version are available in the
[older version's README][readme-0.0.32].

## Usage

After installation, you can use one of the configurations by adding it to the `extends` section in your `.eslintrc` (or `.eslintrc.js`, `.eslintrc.json`, etc.) file, or in an attribute named `eslintConfig` in your `package.json` file.

### ESLint config example

```json
{
"extends": ["yscope/common"]
}
```
After installation, you can create an `eslint.config.mjs` configuration file in the root directory
of your project and export an array of configuration objects.

### Available Configurations

The available configs are:

- `yscope/common`: A general ESLint configuration suitable for a wide range of JavaScript projects.
- `yscope/react`: Tailored ESLint configuration for React applications.
- `yscope/meteor`: A specialized ESLint configuration for Meteor projects.
- `yscope/typescipt`: Designed specifically for TypeScript applications.
- `yscope/jest`: A Jest-specific ESLint configuration intended to override other configurations for Jest test files.

### Jest-Specific Configuration

The Jest configuration is **not standalone** and should be used alongside other configurations. It is intended to
override rules for Jest test files, so it should appear *last* in your `overrides` array.

#### Example Usage

If your project uses Jest, you can add an override for your test files as follows:

```json5
{
"overrides": [
// ...
{
"files": ["test/**/*"],
"extends": ["yscope/jest"]
}
]
}
```

### For TypeScript Configuration

TypeScript-related dependencies are not automatically installed because not every configuration requires them.
Before you can use this configuration, you need to install the dependencies manually.

```shell
npm install --save-dev eslint-import-resolver-typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
```

Then in your ESLint configuration:

```json
{
"extends": [
"yscope/common",
"yscope/typescript"
]
}
```
Some configurations are provided as standalone configuration objects, which can be directly
referenced once imported:
- `CommonConfig`: A general ESLint configuration suitable for a wide range of JavaScript projects.
- `JestConfig`: A specialized ESLint configuration for Jest files.
- `MeteorConfig`: A specialized ESLint configuration for Meteor projects.

The other configurations are provided as a group of configuration objects stored in an array. To use
these configurations, you need to utilize the "spread" (`...`) syntax to unpack the configuration
objects into your own configuration array:
- `StylisticConfigArray`: A configuration for stylistic formatting. It is typically combined with
`CommonConfig`, as shown in the [ESLint config examples](#eslint-config-examples).
- `ReactConfigArray`: A specialized ESLint configuration for React applications.
- `TsConfigArray`: A specialized ESLint configuration for TypeScript projects. A helper
`createTsConfigOverride` is also provided. See [ESLint config examples](#eslint-config-examples) for
details on how to set it up.
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved


### ESLint config examples

1. For use with a CommonJS Node.js project:
```javascript
import globals from "globals";

import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";


const EslintConfig = [
CommonConfig,
...StylisticConfigArray,
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
rules: {
// Your own overrides
},
},
];


export default EslintConfig;
```

2. For use with a JavaScript React.js project:
```javascript
import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
import ReactConfigArray from "eslint-config-yscope/ReactConfigArray.mjs";
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";


const EslintConfig = [
CommonConfig,
...StylisticConfigArray,
...ReactConfigArray,
];


export default EslintConfig;
```

3. For use with a TypeScript React.js project:
```javascript
import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
import ReactConfigArray from "eslint-config-yscope/ReactConfigArray.mjs";
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";
import TsConfigArray from "eslint-config-yscope/TsConfigArray.mjs";


const EslintConfig = [
CommonConfig,

// NOTE: The map below must be placed directly before the spread `StylisticConfigArray`.
Copy link

@coderabbitai coderabbitai bot Jan 4, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Expand the note about configuration order

The note about placement is crucial but lacks context. Consider expanding it to explain why this ordering is necessary.

-// NOTE: The map below must be placed directly before the spread `StylisticConfigArray`.
+// NOTE: The map below must be placed directly before the spread `StylisticConfigArray`.
+// This ordering is required because TsConfigArray extends from a recommended preset that
+// might conflict with stylistic rules. StylisticConfigArray contains overrides to
+// disable these conflicting rules, so it must come after TsConfigArray.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// NOTE: The map below must be placed directly before the spread `StylisticConfigArray`.
// NOTE: The map below must be placed directly before the spread `StylisticConfigArray`.
// This ordering is required because TsConfigArray extends from a recommended preset that
// might conflict with stylistic rules. StylisticConfigArray contains overrides to
// disable these conflicting rules, so it must come after TsConfigArray.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is good for clarity but also could be overly verbose. @kirkrodrigues what do you think?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

...TsConfigArray.map(
(config) => ({
files: [
"**/*.ts",
"**/*.tsx",
],
...config,
})
),
...StylisticConfigArray,

...ReactConfigArray,
];


export default EslintConfig;
```

4. For use with a TypeScript project with multiple `tsconfig.json` files: In projects that include
multiple `tsconfig.json` files for different source types, such as a Vite project created from
the `react-ts` template, you can use the helper function `createTsConfigOverride` to generate
configuration overrides. This ensures proper handling of imports and resolution.
```javascript
import CommonConfig from "eslint-config-yscope/CommonConfig.mjs";
import ReactConfigArray from "eslint-config-yscope/ReactConfigArray.mjs";
import StylisticConfigArray from "eslint-config-yscope/StylisticConfigArray.mjs";
import TsConfigArray, {createTsConfigOverride} from "eslint-config-yscope/TsConfigArray.mjs";


const EslintConfig = [
{
ignores: [
"dist/",
"node_modules/",
],
},
CommonConfig,
...TsConfigArray.map(
(config) => ({
files: [
"**/*.ts",
"**/*.tsx",
],
...config,
})
),
createTsConfigOverride(
[
"src/**/*.ts",
"src/**/*.tsx",
],
"tsconfig.app.json"
),
createTsConfigOverride(
["vite.config.ts"],
"tsconfig.node.json"
),
...StylisticConfigArray,
...ReactConfigArray,
];


export default EslintConfig;
```

## Customization

Each configuration can be further customized and extended as per your project's needs. You can override specific rules by adding them to your ESLint configuration file.
Each configuration can be further customized and extended as per your project's needs. You can
override specific rules by adding them to your ESLint configuration file.

## Contributing

We welcome contributions to the `eslint-config-yscope`! If you have suggestions or improvements, feel free to open an issue or a pull request.
We welcome contributions to the `eslint-config-yscope`! If you have suggestions or improvements,
feel free to open an issue or a pull request.

## License

This project is licensed under Apache License 2.0. Please see the [LICENSE](https://github.com/y-scope/eslint-config-yscope/blob/main/LICENSE) file for more details.
This project is licensed under Apache License 2.0. Please see the [LICENSE][license] file for more
details.
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? GitHub already specifies the license, no? If you want to specify the license on npmjs.org, I assume we need to fill out the license field in package.json?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah we don't have to add this into the README

i'll add the license field to the package.json


[eslint-flat-config]: https://eslint.org/docs/v9.x/use/configure/migration-guide
[license]: https://github.com/y-scope/eslint-config-yscope/blob/main/LICENSE
[readme-0.0.32]: https://github.com/y-scope/eslint-config-yscope/blob/f75571723ff1a6fd734ab82b4a399c2c1c92c5fb/README.md#for-older-nodejs-versions
Loading