-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stylistic configuration and integrate with ESLint
- Loading branch information
Showing
15 changed files
with
220 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ import { avenger } from './src'; | |
|
||
export default avenger({ | ||
typescript: true, | ||
}); | ||
stylistic: true, | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
import fs from 'node:fs/promises' | ||
import { mergeFlatConfigs, typescript } from '../src' | ||
import { builtinRules } from 'eslint/use-at-your-own-risk' | ||
import { flatConfigsToRulesDTS } from 'eslint-typegen/core' | ||
import { javascript } from 'src/configs/javascript' | ||
import fs from 'node:fs/promises'; | ||
import { mergeFlatConfigs, stylistic, typescript } from '../src'; | ||
import { builtinRules } from 'eslint/use-at-your-own-risk'; | ||
import { flatConfigsToRulesDTS } from 'eslint-typegen/core'; | ||
import { javascript } from 'src/configs/javascript'; | ||
|
||
const configs = await mergeFlatConfigs( | ||
{ | ||
plugins: { | ||
'': { | ||
rules: Object.fromEntries(builtinRules.entries()) | ||
} | ||
} | ||
rules: Object.fromEntries(builtinRules.entries()), | ||
}, | ||
}, | ||
}, | ||
javascript(), | ||
typescript() | ||
) | ||
typescript(), | ||
stylistic(), | ||
); | ||
|
||
const configNames = configs.map(i => i.name).filter(Boolean) as string[] | ||
const configNames = configs.map(i => i.name).filter(Boolean) as string[]; | ||
|
||
let dts = await flatConfigsToRulesDTS (configs, { | ||
includeAugmentation: false, | ||
}) | ||
}); | ||
|
||
dts += ` | ||
// Names of all the configs | ||
export type ConfigNames = ${configNames.map(i => `'${i}'`).join(' | ')} | ||
` | ||
`; | ||
|
||
await fs.writeFile('src/eslintype.d.ts', dts) | ||
await fs.writeFile('src/eslintype.d.ts', dts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './javascript' | ||
export * from './typescript' | ||
export * from './javascript'; | ||
export * from './stylistic'; | ||
export * from './typescript'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { EslintFlatConfigItem, IOptionsOverrides, IStylisticConfig } from 'src/types'; | ||
import { loadModule } from '../utils'; | ||
|
||
export const DEFAULT_CONFIG: IStylisticConfig = { | ||
indent: 2, | ||
jsx: true, | ||
quotes: 'single', | ||
semi: true, | ||
}; | ||
|
||
export const stylistic = async ( | ||
options: IStylisticConfig & IOptionsOverrides = {}, | ||
): Promise<EslintFlatConfigItem[]> => { | ||
const { | ||
indent, | ||
jsx, | ||
overrides = {}, | ||
quotes, | ||
semi, | ||
} = { | ||
...DEFAULT_CONFIG, | ||
...options, | ||
}; | ||
|
||
const stylisticPlugin = await loadModule(import('@stylistic/eslint-plugin')); | ||
|
||
const stylisticConfig = stylisticPlugin.configs.customize({ | ||
flat: true, | ||
indent, | ||
jsx, | ||
pluginName: '@stylistic', | ||
quotes, | ||
semi, | ||
}); | ||
|
||
return [ | ||
{ | ||
name: 'sj-distributor/stylistic/rules', | ||
plugins: { | ||
'@stylistic': stylisticPlugin, | ||
}, | ||
rules: { | ||
...stylisticConfig.rules, | ||
|
||
// '@stylistic/object-curly-spacing': ['error', 'always'], // bracketSpacing: true | ||
// '@stylistic/jsx-closing-bracket-location': ['error', 'line-aligned'], // jsxBracketSameLine: true | ||
// '@stylistic/quotes': ['error', 'single'], // singleQuote: true | ||
// '@stylistic/comma-dangle': ['error', 'always-multiline'], // trailingComma: 'all' | ||
// '@stylistic/arrow-parens': ['error', 'as-needed'], // arrowParens: 'avoid' | ||
|
||
curly: ['error', 'all'], | ||
|
||
...overrides, | ||
}, | ||
}, | ||
]; | ||
}; |
Oops, something went wrong.