mirror of
https://github.com/scratchfoundation/eslint-config-scratch.git
synced 2025-07-26 14:12:50 -04:00
feat: better type help, esp. with makeEslintConfig
This commit is contained in:
parent
7d7b277676
commit
497bd2880b
6 changed files with 33 additions and 11 deletions
35
README.md
35
README.md
|
@ -100,21 +100,22 @@ export default makeEslintConfig({
|
|||
|
||||
### Further Customization
|
||||
|
||||
The return value of the `makeEslintConfig` function is a standard ESLint configuration array. This means you can
|
||||
customize your configuration further like this:
|
||||
The first parameter to `makeEslintConfig` is covered above. Any further parameters passed to `makeEslintConfig` are
|
||||
appended to the resulting ESLint configuration array. This means you can customize your configuration further like
|
||||
this:
|
||||
|
||||
```mjs
|
||||
// myProjectRoot/eslint.config.mjs
|
||||
import { makeEslintConfig } from 'eslint-config-scratch'
|
||||
|
||||
export default [
|
||||
...makeEslintConfig({
|
||||
export default makeEslintConfig(
|
||||
{
|
||||
// Optional: enables rules that use type info, some of which work in JS too
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
|
||||
// Optional: specify global variables available in your environment
|
||||
globals: 'browser',
|
||||
}),
|
||||
},
|
||||
// Add custom rules or overrides here
|
||||
{
|
||||
files: ['*.test.js'],
|
||||
|
@ -122,9 +123,12 @@ export default [
|
|||
'no-console': 'off', // Allow console logs in test files
|
||||
},
|
||||
},
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
You could concatenate more configuration objects onto the array returned by `makeEslintConfig` with equivalent
|
||||
results, but this approach offers better editor hints for autocomplete and type checking.
|
||||
|
||||
All ESLint configuration options are available this way. You can use this to handle globals yourself if the simplified
|
||||
`globals` configuration from above doesn't meet your needs:
|
||||
|
||||
|
@ -133,11 +137,11 @@ All ESLint configuration options are available this way. You can use this to han
|
|||
import { makeEslintConfig } from 'eslint-config-scratch'
|
||||
import globals from 'globals'
|
||||
|
||||
export default [
|
||||
...makeEslintConfig({
|
||||
export default makeEslintConfig(
|
||||
{
|
||||
// Optional: enables rules that use type info, some of which work in JS too
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
}),
|
||||
},
|
||||
{
|
||||
files: ['src/main/**.js'],
|
||||
languageOptions: {
|
||||
|
@ -153,7 +157,7 @@ export default [
|
|||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
)
|
||||
```
|
||||
|
||||
Of course, another option would be to place a different `eslint.config.mjs` file in each subdirectory. If you have
|
||||
|
@ -173,6 +177,17 @@ can use the rule sets under `legacy/`:
|
|||
New projects should not use these rule sets. They may disappear in the future. Scratch did not use Prettier at this
|
||||
time, so there is no legacy Prettier configuration.
|
||||
|
||||
Use these rule sets by importing them directly:
|
||||
|
||||
```mjs
|
||||
// myProjectRoot/eslint.config.mjs
|
||||
import webConfig from 'eslint-config-scratch/legacy/es6'
|
||||
import { globalIgnores } from 'eslint/config'
|
||||
|
||||
/** @returns {import('eslint').Linter.Config[]} */
|
||||
export default [...webConfig, globalIgnores(['dist/**/*'])]
|
||||
```
|
||||
|
||||
## Committing
|
||||
|
||||
This project uses [semantic release](https://github.com/semantic-release/semantic-release)
|
||||
|
|
|
@ -72,6 +72,8 @@ const flattenGlobals = globalsIn => {
|
|||
* - a single object as described in the "Specifying Globals" section of the ESLint documentation:
|
||||
* https://eslint.org/docs/latest/use/configure/language-options#using-configuration-files
|
||||
* - an array of zero or more elements, each of which can be either of the above
|
||||
* @param {import('typescript-eslint').InfiniteDepthConfigWithExtends[]} moreConfigs Additional ESLint configurations
|
||||
* to merge with the base configuration.
|
||||
* @example
|
||||
* // eslint.config.mjs
|
||||
* export default makeScratchConfig({tsconfigRootDir: import.meta.dirname, globals: 'node'})
|
||||
|
@ -85,7 +87,7 @@ const flattenGlobals = globalsIn => {
|
|||
* ]
|
||||
* @returns {import('typescript-eslint').ConfigArray} An ESLint configuration array.
|
||||
*/
|
||||
const makeEslintConfig = ({ tsconfigRootDir, globals: globalsIn } = {}) => {
|
||||
const makeEslintConfig = ({ tsconfigRootDir, globals: globalsIn } = {}, ...moreConfigs) => {
|
||||
const flattenedGlobals = flattenGlobals(globalsIn)
|
||||
|
||||
return tseslint.config(
|
||||
|
@ -285,6 +287,7 @@ const makeEslintConfig = ({ tsconfigRootDir, globals: globalsIn } = {}) => {
|
|||
'symbol-description': ['error'],
|
||||
},
|
||||
},
|
||||
...moreConfigs,
|
||||
// Keep `eslintConfigPrettier` last to turn off rules that conflict with Prettier
|
||||
eslintConfigPrettier,
|
||||
)
|
||||
|
|
|
@ -14,6 +14,7 @@ const compat = new FlatCompat({
|
|||
allConfig: js.configs.all,
|
||||
})
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
...compat.extends('eslint:recommended'),
|
||||
jsdoc.configs['flat/recommended'],
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import globals from 'globals'
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{
|
||||
languageOptions: {
|
||||
|
|
|
@ -12,6 +12,7 @@ const compat = new FlatCompat({
|
|||
allConfig: js.configs.all,
|
||||
})
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
...compat.extends('plugin:react/recommended'),
|
||||
{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
{
|
||||
languageOptions: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue