Skip to content

Commit

Permalink
feat(configs): add new options to customize config to assist with mig…
Browse files Browse the repository at this point in the history
…rating from Prettier (#224)

* feat(configs): add new options to customize config to assist users migrating from Prettier

* docs: added new docs page assisting users in migrating from Prettier

* revert(docs): added new docs page assisting users in migrating from Prettier

This reverts commit 4a178f4.

* docs: updated JSDoc comments to reflect Prettier options

---------

Co-authored-by: Seth Murphy <seth.murphy@garavest.com>
  • Loading branch information
eagerestwolf and Seth Murphy authored Jan 1, 2024
1 parent 8f34543 commit d6b4167
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions packages/eslint-plugin/configs/customize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ export interface StylisticCustomizeOptions<Flat extends boolean = true> {
pluginName?: string
/**
* Indentation level
* Similar to the `tabWidth` and `useTabs` options in Prettier
*
* @default 2
*/
indent?: number | 'tab'
/**
* Quote style
* Similar to `singleQuote` option in Prettier
*
* @default 'single'
*/
quotes?: 'single' | 'double'
/**
* Whether to enable semicolons
* Similar to `semi` option in Prettier
*
* @default false
*/
semi?: boolean
Expand All @@ -35,6 +41,39 @@ export interface StylisticCustomizeOptions<Flat extends boolean = true> {
* @default true
*/
jsx?: boolean
/**
* When to enable arrow parenthesis
* Similar to `arrowParens` option in Prettier
*
* @default false
*/
arrowParens?: boolean
/**
* Which brace style to use
* @default 'stroustrup'
*/
braceStyle?: '1tbs' | 'stroustrup' | 'allman'
/**
* Whether to require spaces around braces
* Similar to `bracketSpacing` option in Prettier
*
* @default true
*/
blockSpacing?: boolean
/**
* When to enable prop quoting
* Similar to `quoteProps` option in Prettier
*
* @default 'consistent-as-needed'
*/
quoteProps?: 'always' | 'as-needed' | 'consistent' | 'consistent-as-needed'
/**
* When to enable comma dangles
* Similar to `trailingComma` option in Prettier
*
* @default 'always-multiline'
*/
commaDangle?: 'never' | 'always' | 'always-multiline' | 'only-multiline'
}

type Rules = Partial<{
Expand All @@ -48,21 +87,26 @@ export function customize(options: StylisticCustomizeOptions<false>): Linter.Bas
export function customize(options?: StylisticCustomizeOptions<true>): Linter.FlatConfig
export function customize(options: StylisticCustomizeOptions<boolean> = {}): Linter.FlatConfig | Linter.BaseConfig {
const {
arrowParens = false,
blockSpacing = true,
braceStyle = 'stroustrup',
commaDangle = 'always-multiline',
flat = true,
indent = 2,
jsx = true,
pluginName = '@stylistic',
quoteProps = 'consistent-as-needed',
quotes = 'single',
semi = false,
} = options

let rules: Rules = {
'@stylistic/array-bracket-spacing': ['error', 'never'],
'@stylistic/arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }],
'@stylistic/arrow-parens': ['error', arrowParens ? 'always' : 'as-needed', { requireForBlockBody: true }],
'@stylistic/arrow-spacing': ['error', { after: true, before: true }],
'@stylistic/block-spacing': ['error', 'always'],
'@stylistic/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'@stylistic/comma-dangle': ['error', 'always-multiline'],
'@stylistic/block-spacing': ['error', blockSpacing ? 'always' : 'never'],
'@stylistic/brace-style': ['error', braceStyle, { allowSingleLine: true }],
'@stylistic/comma-dangle': ['error', commaDangle],
'@stylistic/comma-spacing': ['error', { after: true, before: false }],
'@stylistic/comma-style': ['error', 'last'],
'@stylistic/computed-property-spacing': ['error', 'never', { enforceForClassMembers: true }],
Expand Down Expand Up @@ -150,7 +194,7 @@ export function customize(options: StylisticCustomizeOptions<boolean> = {}): Lin
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/operator-linebreak': ['error', 'before'],
'@stylistic/padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }],
'@stylistic/quote-props': ['error', 'consistent-as-needed'],
'@stylistic/quote-props': ['error', quoteProps],
'@stylistic/quotes': ['error', quotes, { allowTemplateLiterals: true, avoidEscape: false }],
'@stylistic/rest-spread-spacing': ['error', 'never'],
'@stylistic/semi': ['error', semi ? 'always' : 'never'],
Expand Down

0 comments on commit d6b4167

Please sign in to comment.