|
1 |
| -# eslint-config |
| 1 | +# eslint-config-ns |
2 | 2 |
|
3 | 3 | [](https://github.com/natterstefan/eslint-config-ns/issues)
|
4 | 4 | [](https://github.com/natterstefan/eslint-config-ns/stargazers)
|
5 | 5 | [](https://github.com/natterstefan/eslint-config-ns/blob/main/LICENSE)
|
6 |
| -[](http://commitizen.github.io/cz-cli/) |
7 | 6 |
|
8 | 7 | 
|
9 | 8 |
|
10 |
| -## Packages |
| 9 | +A comprehensive ESLint configuration for modern JavaScript and TypeScript |
| 10 | +projects, with support for React, Next.js, Jest, and Storybook. This package |
| 11 | +uses the new ESLint flat config format. |
11 | 12 |
|
12 |
| -This monorepo contains multiple packages. Take a look at their READMEs for more |
13 |
| -details. |
| 13 | +## Features |
14 | 14 |
|
15 |
| -- [eslint-config-ns-base](./packages/eslint-config-ns-base/README.md) |
16 |
| -- [eslint-config-ns](./packages/eslint-config-ns/README.md) |
17 |
| -- [eslint-config-ns-ts-base](./packages/eslint-config-ns-ts-base/README.md) |
18 |
| -- [eslint-config-ns-ts](./packages/eslint-config-ns-ts/README.md) |
| 15 | +- 📏 **Modern ESLint Configuration**: Uses the new ESLint flat config format |
| 16 | +- ⚛️ **React Support**: Includes rules for React and React Hooks |
| 17 | +- 📘 **TypeScript Support**: Comprehensive TypeScript rules |
| 18 | +- 🧪 **Testing**: Jest configuration included |
| 19 | +- 📚 **Storybook**: Storybook linting rules |
| 20 | +- ⚡ **Next.js**: Support for Next.js projects |
| 21 | +- 🎨 **Prettier Integration**: Works seamlessly with Prettier |
19 | 22 |
|
20 |
| -### How are they related to each other? |
| 23 | +## Getting Started |
21 | 24 |
|
22 |
| -### JavaScript |
| 25 | +1. Install the required dependencies: |
23 | 26 |
|
24 |
| -- `eslint-config-ns-base` is the base package for JavaScript projects. |
25 |
| -- `eslint-config-ns` extends `eslint-config-ns-base` package and can be used in |
26 |
| - React projects. |
| 27 | +```bash |
| 28 | +# npm |
| 29 | +npm install --save-dev eslint eslint-config-ns prettier |
27 | 30 |
|
28 |
| -### TypeScript |
| 31 | +# yarn |
| 32 | +yarn add --dev eslint eslint-config-ns prettier |
29 | 33 |
|
30 |
| -- `eslint-config-ns-ts-base` extends `eslint-config-ns-base` package and is the |
31 |
| - base package for TypeScript projects. |
32 |
| -- `eslint-config-ns-ts` is the last one in the chain and extends |
33 |
| - `eslint-config-ns-ts-base` and is best used in React TypeScript projects. |
| 34 | +# pnpm |
| 35 | +pnpm add --save-dev eslint eslint-config-ns prettier |
| 36 | +``` |
34 | 37 |
|
35 |
| -## How to release |
| 38 | +1. Create an `eslint.config.mjs` file in your project root: |
36 | 39 |
|
37 |
| -This repository uses GitHub Actions |
38 |
| -([debug locally](https://github.com/nektos/act)) to create a release and update |
39 |
| -the [CHANGELOG](CHANGELOG.md). The implementation is inspired and based on |
40 |
| -[github.com/babel/actions](https://github.com/babel/actions/tree/bb571b895aa20aaa3ee4ef58adcde364416acc9a). |
| 40 | +```javascript |
| 41 | +// eslint.config.mjs |
| 42 | +// @ts-check |
41 | 43 |
|
42 |
| -Either push the tags after running this command to origin, or run the release |
43 |
| -workflow manually on GitHub. |
| 44 | +import { getPresets } from 'eslint-config-ns' |
44 | 45 |
|
45 |
| -### Manually trigger release |
| 46 | +/** |
| 47 | + * @type {Array<import('eslint').Linter.Config>} |
| 48 | + */ |
| 49 | +export default await getPresets( |
| 50 | + // Base config |
| 51 | + 'typescript', // or use 'javascript' for JS-only projects |
46 | 52 |
|
47 |
| -```bash |
48 |
| -yarn lerna:version |
49 |
| -git push --follow-tags |
50 |
| -# wait until GitHub Action finishes and then run |
51 |
| -yarn lerna:publish |
| 53 | + // Optional extensions based on your project needs |
| 54 | + 'react', |
| 55 | + 'jest', |
| 56 | + 'prettier', |
| 57 | + // 'next', // Uncomment if using Next.js |
| 58 | + // 'storybook', // Uncomment if using Storybook |
| 59 | +) |
52 | 60 | ```
|
53 | 61 |
|
54 |
| -### Manually create Changelog entry |
| 62 | +1. Add |
| 63 | + [globals](https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables) |
| 64 | + (like browser or Node.js APIs) if you need them: |
55 | 65 |
|
56 |
| -```bash |
57 |
| -npx lerna-changelog --from <tag> --to <tag> |
| 66 | +```javascript |
| 67 | +// eslint.config.mjs |
| 68 | +// @ts-check |
| 69 | + |
| 70 | +import { getPresets } from 'eslint-config-ns' |
| 71 | + |
| 72 | +/** |
| 73 | + * @type {Array<import('eslint').Linter.Config>} |
| 74 | + */ |
| 75 | +export default [ |
| 76 | + ...(await getPresets('typescript', 'react', 'jest', 'prettier')), |
| 77 | + { |
| 78 | + languageOptions: { |
| 79 | + globals: { |
| 80 | + ...globals.browser, |
| 81 | + ...globals.node, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | +] |
| 86 | +``` |
| 87 | + |
| 88 | +### Prettier and TypeScript |
| 89 | + |
| 90 | +1. To set up Prettier, add to your `package.json`: |
| 91 | + |
| 92 | +```json |
| 93 | +{ |
| 94 | + "prettier": "eslint-config-ns/prettier.config.js" |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +1. If you use TypeScript, you can extend the provided tsconfig: |
| 99 | + |
| 100 | +```json |
| 101 | +{ |
| 102 | + "extends": "eslint-config-ns/tsconfig.json" |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Usage |
| 107 | + |
| 108 | +Create an `eslint.config.mjs` file in your project root and import the |
| 109 | +configurations you need: |
| 110 | + |
| 111 | +```javascript |
| 112 | +// @ts-check |
| 113 | + |
| 114 | +import { getPresets } from 'eslint-config-ns' |
| 115 | + |
| 116 | +/** |
| 117 | + * @type {Array<import('eslint').Linter.Config>} |
| 118 | + */ |
| 119 | +export default await getPresets( |
| 120 | + // 'javascript', |
| 121 | + 'jest', |
| 122 | + // 'next', // Uncomment if using Next.js |
| 123 | + 'prettier', |
| 124 | + 'react', |
| 125 | + 'storybook', |
| 126 | + 'typescript', // contains JavaScript |
| 127 | +) |
| 128 | +``` |
| 129 | + |
| 130 | +### Available Presets |
| 131 | + |
| 132 | +- `javascript` - Base JavaScript rules |
| 133 | +- `jest` - Jest testing rules |
| 134 | +- `next` - Next.js rules |
| 135 | +- `prettier` - Prettier integration |
| 136 | +- `react` - React and JSX rules |
| 137 | +- `storybook` - Storybook rules |
| 138 | +- `typescript` - TypeScript rules (includes JavaScript rules) |
| 139 | + |
| 140 | +## Configuration Examples |
| 141 | + |
| 142 | +### Basic JavaScript Project |
| 143 | + |
| 144 | +```javascript |
| 145 | +// eslint.config.js |
| 146 | +import { getPresets } from 'eslint-config-ns' |
| 147 | + |
| 148 | +export default await getPresets('javascript', 'prettier') |
| 149 | +``` |
| 150 | + |
| 151 | +### React TypeScript Project |
| 152 | + |
| 153 | +```javascript |
| 154 | +// eslint.config.js |
| 155 | +import { getPresets } from 'eslint-config-ns' |
| 156 | + |
| 157 | +export default await getPresets( |
| 158 | + 'typescript', // includes JavaScript rules |
| 159 | + 'react', |
| 160 | + 'prettier', |
| 161 | +) |
| 162 | +``` |
| 163 | + |
| 164 | +### Next.js Project |
| 165 | + |
| 166 | +```javascript |
| 167 | +// eslint.config.js |
| 168 | +import { getPresets } from 'eslint-config-ns' |
| 169 | + |
| 170 | +export default await getPresets('typescript', 'react', 'next', 'prettier') |
| 171 | +``` |
| 172 | + |
| 173 | +### Full-Featured Project |
| 174 | + |
| 175 | +```javascript |
| 176 | +// eslint.config.js |
| 177 | +import { getPresets } from 'eslint-config-ns' |
| 178 | + |
| 179 | +export default await getPresets( |
| 180 | + 'typescript', |
| 181 | + 'react', |
| 182 | + 'jest', |
| 183 | + 'storybook', |
| 184 | + 'next', |
| 185 | + 'prettier', |
| 186 | +) |
| 187 | +``` |
| 188 | + |
| 189 | +### Custom Rules |
| 190 | + |
| 191 | +You can add your own custom rules by spreading the presets and adding your |
| 192 | +configuration: |
| 193 | + |
| 194 | +```javascript |
| 195 | +// eslint.config.js |
| 196 | +import { getPresets } from 'eslint-config-ns' |
| 197 | + |
| 198 | +export default [ |
| 199 | + ...(await getPresets('typescript', 'react', 'prettier')), |
| 200 | + { |
| 201 | + // Your custom rules |
| 202 | + rules: { |
| 203 | + 'no-console': 'warn', |
| 204 | + // Add any other custom rules |
| 205 | + }, |
| 206 | + }, |
| 207 | +] |
| 208 | +``` |
| 209 | + |
| 210 | +## IDE Integration |
| 211 | + |
| 212 | +### VSCode Integration |
| 213 | + |
| 214 | +1. Install the following extensions: |
| 215 | + |
| 216 | +- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) |
| 217 | +- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) |
| 218 | + |
| 219 | +1. Add the following to your VSCode settings (`.vscode/settings.json`): |
| 220 | + |
| 221 | +```json |
| 222 | +{ |
| 223 | + "editor.codeActionsOnSave": { |
| 224 | + "source.fixAll.eslint": "always" |
| 225 | + }, |
| 226 | + "editor.defaultFormatter": "esbenp.prettier-vscode", |
| 227 | + "editor.formatOnSave": true |
| 228 | +} |
58 | 229 | ```
|
59 | 230 |
|
60 |
| -### Automatically with GitHub Actions |
| 231 | +### CI Integration |
| 232 | + |
| 233 | +To validate your code in a CI pipeline, add the following to your |
| 234 | +`package.json`: |
| 235 | + |
| 236 | +```json |
| 237 | +{ |
| 238 | + "scripts": { |
| 239 | + "lint": "eslint src && prettier src --check" |
| 240 | + } |
| 241 | +} |
| 242 | +``` |
| 243 | + |
| 244 | +## Requirements |
| 245 | + |
| 246 | +- Node.js >=20 |
| 247 | +- ESLint >=9.x |
| 248 | +- Prettier >=3.x |
| 249 | + |
| 250 | +## Contributing |
61 | 251 |
|
62 |
| -Manually invoke the |
63 |
| -[GitHub Action release](https://github.com/natterstefan/eslint-config-ns/actions/workflows/release.yml) |
64 |
| -and wait until it finishes. |
| 252 | +Contributions are welcome! Please feel free to submit a Pull Request. |
65 | 253 |
|
66 |
| -Once the release was created with GitHub Actions, publish the packages manually |
67 |
| -to npm with `yarn lerna:publish`. |
| 254 | +## Other Configs |
68 | 255 |
|
69 |
| -Attention: make sure the Pull Requests have labels _before_ you merge them. The |
70 |
| -label (e.g. `enhancement` and `bug`) will be used to create the CHANGELOG. |
| 256 | +- <https://github.com/molindo/eslint-config-molindo> |
71 | 257 |
|
72 | 258 | ## LICENSE
|
73 | 259 |
|
|
0 commit comments