@shayanthenerd/eslint-config
Version:
A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style
233 lines (232 loc) • 6.36 kB
JavaScript
import { isEnabled } from "../utils/isEnabled.mjs";
import { defaultOptions } from "../helpers/options/defaultOptions.mjs";
//#region src/rules/stylistic.ts
function getStylisticRules(options) {
const { stylistic } = options.configs;
const { semi, quotes, indent, jsxQuotes, arrowParens, trailingComma, maxLineLength, maxAttributesPerLine, memberDelimiterStyle, maxConsecutiveEmptyLines } = isEnabled(stylistic) ? stylistic : defaultOptions.configs.stylistic;
return {
"@stylistic/array-bracket-newline": ["warn", "consistent"],
"@stylistic/array-bracket-spacing": "warn",
"@stylistic/arrow-parens": ["warn", arrowParens],
"@stylistic/arrow-spacing": "warn",
"@stylistic/block-spacing": "warn",
"@stylistic/brace-style": [
"warn",
"1tbs",
{ allowSingleLine: true }
],
"@stylistic/comma-dangle": ["warn", trailingComma],
"@stylistic/comma-spacing": "warn",
"@stylistic/comma-style": "warn",
"@stylistic/computed-property-spacing": "warn",
"@stylistic/dot-location": ["warn", "property"],
"@stylistic/eol-last": "warn",
"@stylistic/exp-list-style": "warn",
"@stylistic/function-call-argument-newline": ["warn", "consistent"],
"@stylistic/generator-star-spacing": ["warn", "after"],
"@stylistic/implicit-arrow-linebreak": ["warn", "beside"],
"@stylistic/indent": [
"warn",
indent,
{
tabLength: indent,
SwitchCase: 1,
flatTernaryExpressions: true
}
],
"@stylistic/indent-binary-ops": ["warn", indent],
"@stylistic/jsx-closing-bracket-location": "warn",
"@stylistic/jsx-closing-tag-location": "warn",
"@stylistic/jsx-curly-brace-presence": "warn",
"@stylistic/jsx-curly-newline": "warn",
"@stylistic/jsx-curly-spacing": "warn",
"@stylistic/jsx-equals-spacing": "warn",
"@stylistic/jsx-first-prop-new-line": "warn",
"@stylistic/jsx-function-call-newline": "warn",
"@stylistic/jsx-indent-props": ["warn", indent],
"@stylistic/jsx-max-props-per-line": ["warn", { maximum: {
multi: 1,
single: maxAttributesPerLine
} }],
"@stylistic/jsx-one-expression-per-line": "warn",
"@stylistic/exp-jsx-props-style": ["warn", { singleLine: { maxItems: maxAttributesPerLine } }],
"@stylistic/jsx-quotes": ["warn", jsxQuotes],
"@stylistic/jsx-tag-spacing": "warn",
"@stylistic/jsx-wrap-multilines": "warn",
"@stylistic/key-spacing": "warn",
"@stylistic/keyword-spacing": "warn",
"@stylistic/linebreak-style": "warn",
"@stylistic/lines-around-comment": ["warn", {
beforeBlockComment: false,
applyDefaultIgnorePatterns: false,
ignorePattern: "@ts|eslint"
}],
"@stylistic/max-len": ["warn", {
tabWidth: indent,
code: maxLineLength,
ignoreUrls: true,
ignoreStrings: true,
ignoreComments: true,
ignoreRegExpLiterals: true,
ignoreTrailingComments: true,
ignoreTemplateLiterals: true
}],
"@stylistic/max-statements-per-line": "warn",
"@stylistic/member-delimiter-style": ["warn", {
singleline: { delimiter: memberDelimiterStyle },
multiline: {
delimiter: memberDelimiterStyle,
requireLast: trailingComma !== "never"
}
}],
"@stylistic/new-parens": "warn",
"@stylistic/no-confusing-arrow": "warn",
"@stylistic/no-extra-semi": "warn",
"@stylistic/no-floating-decimal": "warn",
"@stylistic/no-mixed-operators": "warn",
"@stylistic/no-mixed-spaces-and-tabs": "warn",
"@stylistic/no-multi-spaces": "warn",
"@stylistic/no-multiple-empty-lines": ["warn", {
maxBOF: 0,
maxEOF: 0,
max: maxConsecutiveEmptyLines
}],
"@stylistic/no-tabs": "warn",
"@stylistic/no-trailing-spaces": "warn",
"@stylistic/no-whitespace-before-property": "warn",
"@stylistic/nonblock-statement-body-position": "warn",
"@stylistic/object-curly-newline": ["warn", {
multiline: true,
consistent: true
}],
"@stylistic/object-curly-spacing": [
"warn",
"always",
{ emptyObjects: "never" }
],
"@stylistic/object-property-newline": ["warn", { allowAllPropertiesOnSameLine: true }],
"@stylistic/operator-linebreak": [
"warn",
"none",
{ overrides: {
"=": "after",
"?": "before",
":": "before",
"|": "before",
"&": "before"
} }
],
"@stylistic/padded-blocks": [
"warn",
"never",
{ allowSingleLineBlocks: true }
],
"@stylistic/padding-line-between-statements": [
"warn",
{
prev: "*",
next: [
"do",
"try",
"for",
"iife",
"with",
"class",
"block",
"while",
"export",
"function",
"directive",
"block-like",
"cjs-export",
"multiline-block-like"
],
blankLine: "always"
},
{
prev: "import",
next: "*",
blankLine: "always"
},
{
prev: "import",
next: "import",
blankLine: "any"
},
{
prev: "export",
next: "export",
blankLine: "any"
},
{
prev: "function-overload",
next: "function",
blankLine: "never"
},
{
prev: [
"const",
"let",
"using",
"var"
],
next: "block-like",
blankLine: "any"
},
{
prev: "block-like",
next: "*",
blankLine: "always"
},
{
prev: [
"if",
"switch",
"try",
"for",
"while",
"do",
"with"
],
next: [
"break",
"continue",
"return",
"throw"
],
blankLine: "any"
},
{
prev: ["case", "default"],
next: ["case", "default"],
blankLine: "never"
}
],
"@stylistic/quote-props": ["warn", "consistent-as-needed"],
"@stylistic/quotes": ["warn", quotes],
"@stylistic/rest-spread-spacing": "warn",
"@stylistic/semi": ["warn", semi],
"@stylistic/semi-spacing": "warn",
"@stylistic/semi-style": "warn",
"@stylistic/space-before-blocks": "warn",
"@stylistic/space-before-function-paren": ["warn", {
named: "never",
catch: "always",
anonymous: "always",
asyncArrow: "always"
}],
"@stylistic/space-in-parens": "warn",
"@stylistic/space-infix-ops": "warn",
"@stylistic/space-unary-ops": "warn",
"@stylistic/switch-colon-spacing": "warn",
"@stylistic/template-curly-spacing": "warn",
"@stylistic/template-tag-spacing": "warn",
"@stylistic/type-annotation-spacing": "warn",
"@stylistic/type-named-tuple-spacing": "warn",
"@stylistic/wrap-iife": "warn",
"@stylistic/wrap-regex": "warn",
"@stylistic/yield-star-spacing": "warn"
};
}
//#endregion
export { getStylisticRules };