|
| 1 | +# @strv/eslint-config-web |
| 2 | + |
| 3 | +- [@strv/eslint-config-web](#strveslint-config-web) |
| 4 | + - [Installation](#installation) |
| 5 | + - [Rulesets](#rulesets) |
| 6 | + - [Usage](#usage) |
| 7 | + - [Customizations](#customizations) |
| 8 | + - [Formatters](#formatters) |
| 9 | + - [Unicorn \& Stylistic](#unicorn--stylistic) |
| 10 | + - [Other config](#other-config) |
| 11 | + - [VSCode](#vscode) |
| 12 | + - [License](#license) |
| 13 | + > Configuration for Web projects. |
| 14 | +
|
| 15 | +## Installation |
| 16 | + |
| 17 | +```sh |
| 18 | +# npm |
| 19 | +npm install -D @strv/eslint-config-web |
| 20 | +# yarn |
| 21 | +yard add -D @strv/eslint-config-web |
| 22 | +# pnpm |
| 23 | +pnpm add -D @strv/eslint-config-web |
| 24 | +``` |
| 25 | + |
| 26 | +## Rulesets |
| 27 | + |
| 28 | +- `'@strv/eslint-config-web'`: STRV Frontend Ruleset that focuses on code correctness for web projects, which use TypeScript and React. |
| 29 | + |
| 30 | +This ruleset is based on [Antfu ESLint Ruleset](https://github.com/antfu/eslint-config). If you are interested in more details about the rules, you can check the ruleset in [Config Inspector](https://eslint-config.antfu.me/). |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +```js |
| 35 | +import config from "@strv/eslint-config-web"; |
| 36 | + |
| 37 | +export default config; |
| 38 | +``` |
| 39 | + |
| 40 | +### Customizations |
| 41 | + |
| 42 | +```js |
| 43 | +import { createConfig } from "@strv/eslint-config-web"; |
| 44 | + |
| 45 | +const config = createConfig( |
| 46 | + { |
| 47 | + ignores: ["devops/*", "custom-scripts/*"], |
| 48 | + unicornOverrides: { |
| 49 | + "unicorn/filename-case": [ |
| 50 | + "error", |
| 51 | + { |
| 52 | + case: "camelCase", |
| 53 | + ignore: ["pull_request_template.md"], |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + stylisticOverrides: { |
| 58 | + "style/arrow-parens": ["error", "always"], |
| 59 | + }, |
| 60 | + }, |
| 61 | + { |
| 62 | + files: ["**/*"], |
| 63 | + rules: { |
| 64 | + "check-file/filename-blocklist": "off", |
| 65 | + }, |
| 66 | + }, |
| 67 | +); |
| 68 | + |
| 69 | +export default config; |
| 70 | +``` |
| 71 | + |
| 72 | +#### Formatters |
| 73 | + |
| 74 | +If you would like to see more details about the exposed option `formatters`, please check the [official documentation](https://github.com/antfu/eslint-config?tab=readme-ov-file#formatters). |
| 75 | + |
| 76 | +#### Unicorn & Stylistic |
| 77 | + |
| 78 | +`unicornOverrides` and `stylisticOverrides` provide an option to adjust specific plugin rules. |
| 79 | + |
| 80 | +`unicorn/*` rules should be listed in `unicornOverrides`, and `style/*` rules should be listed in `stylisticOverrides`. |
| 81 | + |
| 82 | +#### Other config |
| 83 | + |
| 84 | +If needed, you can pass additional flat config objects as arguments with unlimited config options. |
| 85 | + |
| 86 | +```js |
| 87 | +import { createConfig } from "@strv/eslint-config-web"; |
| 88 | + |
| 89 | +const config = createConfig( |
| 90 | + // Create Config Options |
| 91 | + { |
| 92 | + ignores: ["devops/*"], |
| 93 | + }, |
| 94 | + // Flat Config object without restrictions |
| 95 | + { |
| 96 | + files: ["**/*"], |
| 97 | + rules: { |
| 98 | + "antfu/top-level-function": "off", |
| 99 | + "check-file/filename-blocklist": "off", |
| 100 | + }, |
| 101 | + }, |
| 102 | + { |
| 103 | + files: ["cypress/*"], |
| 104 | + plugins: { |
| 105 | + // integrate cypress plugin |
| 106 | + } |
| 107 | + rules: { |
| 108 | + // cypress specific rules |
| 109 | + }, |
| 110 | + }, |
| 111 | +); |
| 112 | + |
| 113 | +export default config; |
| 114 | +``` |
| 115 | + |
| 116 | +### VSCode |
| 117 | + |
| 118 | +Update the `.vscode/settings.json` on you project to include this setup: |
| 119 | + |
| 120 | +```json |
| 121 | + // Disable the default formatter, use eslint instead |
| 122 | + "prettier.enable": false, |
| 123 | + "editor.formatOnSave": false, |
| 124 | + |
| 125 | + // Auto fix |
| 126 | + "editor.codeActionsOnSave": { |
| 127 | + "source.fixAll.eslint": "explicit", |
| 128 | + "source.organizeImports": "never" |
| 129 | + }, |
| 130 | + |
| 131 | + // Silent the stylistic rules in you IDE, but still auto fix them |
| 132 | + "eslint.rules.customizations": [ |
| 133 | + { "rule": "style/*", "severity": "off", "fixable": true }, |
| 134 | + { "rule": "format/*", "severity": "off", "fixable": true }, |
| 135 | + { "rule": "*-indent", "severity": "off", "fixable": true }, |
| 136 | + { "rule": "*-spacing", "severity": "off", "fixable": true }, |
| 137 | + { "rule": "*-spaces", "severity": "off", "fixable": true }, |
| 138 | + { "rule": "*-order", "severity": "off", "fixable": true }, |
| 139 | + { "rule": "*-dangle", "severity": "off", "fixable": true }, |
| 140 | + { "rule": "*-newline", "severity": "off", "fixable": true }, |
| 141 | + { "rule": "*quotes", "severity": "off", "fixable": true }, |
| 142 | + { "rule": "*semi", "severity": "off", "fixable": true } |
| 143 | + ], |
| 144 | + |
| 145 | + // Enable eslint for all supported languages |
| 146 | + "eslint.validate": [ |
| 147 | + "javascript", |
| 148 | + "javascriptreact", |
| 149 | + "typescript", |
| 150 | + "typescriptreact", |
| 151 | + "vue", |
| 152 | + "html", |
| 153 | + "markdown", |
| 154 | + "json", |
| 155 | + "jsonc", |
| 156 | + "yaml", |
| 157 | + "toml", |
| 158 | + "xml", |
| 159 | + "gql", |
| 160 | + "graphql", |
| 161 | + "astro", |
| 162 | + "svelte", |
| 163 | + "css", |
| 164 | + "less", |
| 165 | + "scss", |
| 166 | + "pcss", |
| 167 | + "postcss" |
| 168 | + ], |
| 169 | +``` |
| 170 | + |
| 171 | +## License |
| 172 | + |
| 173 | +See the [LICENSE](LICENSE) file for information. |
0 commit comments