@stylistic/eslint-plugin
Advanced tools
Comparing version 2.13.0 to 3.0.0
@@ -23,4 +23,4 @@ 'use strict'; | ||
var implicitArrowLinebreak = require('./rules/implicit-arrow-linebreak.js'); | ||
var indentBinaryOps = require('./rules/indent-binary-ops.js'); | ||
var indent = require('./rules/indent.js'); | ||
var indentBinaryOps = require('./rules/indent-binary-ops.js'); | ||
var jsxChildElementSpacing = require('./rules/jsx-child-element-spacing.js'); | ||
@@ -35,4 +35,4 @@ var jsxClosingBracketLocation = require('./rules/jsx-closing-bracket-location.js'); | ||
var jsxFunctionCallNewline = require('./rules/jsx-function-call-newline.js'); | ||
var jsxIndentProps = require('./rules/jsx-indent-props.js'); | ||
var jsxIndent = require('./rules/jsx-indent.js'); | ||
var jsxIndentProps = require('./rules/jsx-indent-props.js'); | ||
var jsxMaxPropsPerLine = require('./rules/jsx-max-props-per-line.js'); | ||
@@ -83,5 +83,5 @@ var jsxNewline = require('./rules/jsx-newline.js'); | ||
var restSpreadSpacing = require('./rules/rest-spread-spacing.js'); | ||
var semi = require('./rules/semi.js'); | ||
var semiSpacing = require('./rules/semi-spacing.js'); | ||
var semiStyle = require('./rules/semi-style.js'); | ||
var semi = require('./rules/semi.js'); | ||
var spaceBeforeBlocks = require('./rules/space-before-blocks.js'); | ||
@@ -88,0 +88,0 @@ var spaceBeforeFunctionParen = require('./rules/space-before-function-paren.js'); |
@@ -29,4 +29,4 @@ 'use strict'; | ||
require('./rules/implicit-arrow-linebreak.js'); | ||
require('./rules/indent-binary-ops.js'); | ||
require('./rules/indent.js'); | ||
require('./rules/indent-binary-ops.js'); | ||
require('./rules/jsx-child-element-spacing.js'); | ||
@@ -41,4 +41,4 @@ require('./rules/jsx-closing-bracket-location.js'); | ||
require('./rules/jsx-function-call-newline.js'); | ||
require('./rules/jsx-indent-props.js'); | ||
require('./rules/jsx-indent.js'); | ||
require('./rules/jsx-indent-props.js'); | ||
require('./rules/jsx-max-props-per-line.js'); | ||
@@ -90,5 +90,5 @@ require('./rules/jsx-newline.js'); | ||
require('./rules/rest-spread-spacing.js'); | ||
require('./rules/semi.js'); | ||
require('./rules/semi-spacing.js'); | ||
require('./rules/semi-style.js'); | ||
require('./rules/semi.js'); | ||
require('./rules/space-before-blocks.js'); | ||
@@ -95,0 +95,0 @@ require('./rules/space-before-function-paren.js'); |
@@ -45,33 +45,3 @@ 'use strict'; | ||
const sourceCode = context.sourceCode; | ||
const exceptions = { | ||
ArrayPattern: true, | ||
ArrowFunctionExpression: true, | ||
CallExpression: true, | ||
FunctionDeclaration: true, | ||
FunctionExpression: true, | ||
ImportDeclaration: true, | ||
ObjectPattern: true, | ||
NewExpression: true, | ||
ExportAllDeclaration: true, | ||
ExportNamedDeclaration: true, | ||
ImportExpression: true, | ||
SequenceExpression: true, | ||
ClassDeclaration: true, | ||
ClassExpression: true, | ||
TSDeclareFunction: true, | ||
TSFunctionType: true, | ||
TSConstructorType: true, | ||
TSEmptyBodyFunctionExpression: true, | ||
TSEnumBody: true, | ||
TSTypeLiteral: true, | ||
TSIndexSignature: true, | ||
TSMethodSignature: true, | ||
TSCallSignatureDeclaration: true, | ||
TSConstructSignatureDeclaration: true, | ||
TSInterfaceBody: true, | ||
TSInterfaceDeclaration: true, | ||
TSTupleType: true, | ||
TSTypeParameterDeclaration: true, | ||
TSTypeParameterInstantiation: true | ||
}; | ||
const exceptions = {}; | ||
if (context.options.length === 2 && Object.prototype.hasOwnProperty.call(context.options[1], "exceptions")) { | ||
@@ -78,0 +48,0 @@ (_a = context.options)[1] ?? (_a[1] = { exceptions: {} }); |
@@ -85,3 +85,6 @@ 'use strict'; | ||
node, | ||
loc: leftToken.loc.start, | ||
loc: { | ||
start: leftToken.loc.end, | ||
end: rightToken.loc.start | ||
}, | ||
messageId: "unexpectedWhitespace", | ||
@@ -97,9 +100,6 @@ fix(fixer) { | ||
} | ||
if (!hasNewline) { | ||
return fixer.removeRange([ | ||
leftToken.range[1], | ||
rightToken.range[0] | ||
]); | ||
} | ||
return null; | ||
return fixer.removeRange([ | ||
leftToken.range[1], | ||
rightToken.range[0] | ||
]); | ||
} | ||
@@ -119,3 +119,6 @@ }); | ||
node, | ||
loc: leftToken.loc.start, | ||
loc: { | ||
start: leftToken.loc.end, | ||
end: rightToken.loc.start | ||
}, | ||
messageId, | ||
@@ -142,3 +145,6 @@ fix(fixer) { | ||
node, | ||
loc: leftToken.loc.start, | ||
loc: { | ||
start: leftToken.loc.end, | ||
end: rightToken.loc.start | ||
}, | ||
messageId: "missing", | ||
@@ -152,3 +158,6 @@ fix(fixer) { | ||
node, | ||
loc: leftToken.loc.start, | ||
loc: { | ||
start: leftToken.loc.end, | ||
end: rightToken.loc.start | ||
}, | ||
messageId: "unexpectedNewline", | ||
@@ -155,0 +164,0 @@ fix(fixer) { |
@@ -107,3 +107,3 @@ 'use strict'; | ||
const lastTokenOfLineLeft = lastTokenOfLine(tokenLeft.loc.start.line); | ||
const needAdditionIndent = firstTokenOfLineLeft?.type === "Keyword" && !["typeof", "instanceof", "this"].includes(firstTokenOfLineLeft.value) || firstTokenOfLineLeft?.type === "Identifier" && firstTokenOfLineLeft.value === "type" && isTypeKeywordOfNode(firstTokenOfLineLeft, node) || [":", "[", "(", "<"].concat(utils.ASSIGNMENT_OPERATOR).includes(lastTokenOfLineLeft?.value || "") || ["[", "(", "=>", ":"].concat(utils.ASSIGNMENT_OPERATOR).includes(tokenBeforeAll?.value || "") && firstTokenOfLineLeft?.loc.start.line === tokenBeforeAll?.loc.start.line || ["||", "&&"].includes(lastTokenOfLineLeft?.value || "") && node.loc.start.line === tokenLeft.loc.start.line && node.loc.start.column !== getIndentOfLine(node.loc.start.line).length; | ||
const needAdditionIndent = firstTokenOfLineLeft?.type === "Keyword" && !["typeof", "instanceof", "this"].includes(firstTokenOfLineLeft.value) || firstTokenOfLineLeft?.type === "Identifier" && firstTokenOfLineLeft.value === "type" && isTypeKeywordOfNode(firstTokenOfLineLeft, node) || [":", "[", "(", "<"].concat(utils.ASSIGNMENT_OPERATOR).includes(lastTokenOfLineLeft?.value || "") || ["[", "(", "=>", ":"].concat(utils.ASSIGNMENT_OPERATOR).includes(tokenBeforeAll?.value || "") && firstTokenOfLineLeft?.loc.start.line === tokenBeforeAll?.loc.start.line; | ||
const needSubtractionIndent = lastTokenOfLineLeft?.value === ")" && isGreaterThanCloseBracketOfLine(tokenLeft.loc.start.line) && !["]", ")", "}"].includes(firstTokenOfLineLeft?.value || ""); | ||
@@ -110,0 +110,0 @@ const indentLeft = getIndentOfLine(tokenLeft.loc.start.line); |
@@ -82,3 +82,3 @@ 'use strict'; | ||
return 0; | ||
const actualLocale = options.locale === "auto" ? void 0 : options.locale; | ||
const actualLocale = options.locale === "auto" ? undefined : options.locale; | ||
if (options.ignoreCase) { | ||
@@ -384,3 +384,3 @@ aProp = aProp.toLowerCase(); | ||
} | ||
if (!noSortAlphabetically && (ignoreCase || locale !== "auto" ? previousPropName.localeCompare(currentPropName, locale === "auto" ? void 0 : locale) > 0 : previousPropName > currentPropName)) { | ||
if (!noSortAlphabetically && (ignoreCase || locale !== "auto" ? previousPropName.localeCompare(currentPropName, locale === "auto" ? undefined : locale) > 0 : previousPropName > currentPropName)) { | ||
reportNodeAttribute(decl, "sortPropsByAlpha", node, context, nodeReservedList); | ||
@@ -387,0 +387,0 @@ return memo; |
@@ -124,4 +124,7 @@ 'use strict'; | ||
if (tokenBefore.loc.end.line < start.line) { | ||
const textBetween = sourceCode.getText().slice(tokenBefore.range[1], node.range[0]).trim(); | ||
const indent = start.column > 0 ? " ".repeat(start.column) : ""; | ||
const textBefore = sourceCode.getText().slice(tokenBefore.range[1], node.range[0]).trim(); | ||
const isTab = /^\t/.test(sourceCode.lines[start.line - 1]); | ||
const INDENT = isTab ? " " : " "; | ||
const indentBefore = INDENT.repeat(start.column); | ||
const indentAfter = INDENT.repeat(Math.max(0, start.column - (isTab ? 1 : 2))); | ||
context.report({ | ||
@@ -136,5 +139,5 @@ node, | ||
`${trimTokenBeforeNewline(tokenBefore)}( | ||
${indent}${textBetween}${textBetween.length > 0 ? ` | ||
${indent}` : ""}${sourceCode.getText(node)} | ||
${start.column > 0 ? " ".repeat(start.column - 2) : ""})` | ||
${indentBefore}${textBefore}${textBefore.length > 0 ? ` | ||
${indentBefore}` : ""}${sourceCode.getText(node)} | ||
${indentAfter})` | ||
) | ||
@@ -141,0 +144,0 @@ }); |
@@ -711,3 +711,3 @@ 'use strict'; | ||
if (prevAlignedNode !== prevNode) | ||
prevAlignedNode = void 0; | ||
prevAlignedNode = undefined; | ||
if (prevAlignedNode && continuesAlignGroup(prevAlignedNode, node)) { | ||
@@ -714,0 +714,0 @@ currentAlignGroup.push(node); |
@@ -34,3 +34,3 @@ 'use strict'; | ||
const config = context.options[0] || {}; | ||
const allowParens = config.allowParens || config.allowParens === void 0; | ||
const allowParens = config.allowParens || config.allowParens === undefined; | ||
const onlyOneSimpleParam = config.onlyOneSimpleParam; | ||
@@ -37,0 +37,0 @@ const sourceCode = context.sourceCode; |
@@ -309,3 +309,3 @@ 'use strict'; | ||
currentNode = currentNode.parent; | ||
if (currentNode === null || currentNode === void 0) | ||
if (currentNode === null || currentNode === undefined) | ||
throw new Error("Nodes are not in the ancestor-descendant relationship."); | ||
@@ -312,0 +312,0 @@ path.push(currentNode); |
@@ -277,4 +277,4 @@ 'use strict'; | ||
const shouldCheckPenultimate = options.arraysInObjectsException && astUtils.isClosingBracketToken(penultimate) || options.objectsInObjectsException && astUtils.isClosingBraceToken(penultimate); | ||
const penultimateType = shouldCheckPenultimate ? sourceCode.getNodeByRangeIndex(penultimate.range[0]).type : void 0; | ||
const closingCurlyBraceMustBeSpaced = options.arraysInObjectsException && penultimateType === utils$1.AST_NODE_TYPES.TSTupleType || options.objectsInObjectsException && penultimateType !== void 0 && [ | ||
const penultimateType = shouldCheckPenultimate ? sourceCode.getNodeByRangeIndex(penultimate.range[0]).type : undefined; | ||
const closingCurlyBraceMustBeSpaced = options.arraysInObjectsException && penultimateType === utils$1.AST_NODE_TYPES.TSTupleType || options.objectsInObjectsException && penultimateType !== undefined && [ | ||
utils$1.AST_NODE_TYPES.TSMappedType, | ||
@@ -281,0 +281,0 @@ utils$1.AST_NODE_TYPES.TSTypeLiteral |
@@ -73,3 +73,11 @@ 'use strict'; | ||
allowTemplateLiterals: { | ||
type: "boolean" | ||
anyOf: [ | ||
{ | ||
type: "boolean" | ||
}, | ||
{ | ||
type: "string", | ||
enum: ["never", "avoidEscape", "always"] | ||
} | ||
] | ||
}, | ||
@@ -93,8 +101,20 @@ ignoreStringLiterals: { | ||
const options = context.options[1]; | ||
const allowTemplateLiterals = options && typeof options === "object" && options.allowTemplateLiterals === true; | ||
const ignoreStringLiterals = options && typeof options === "object" && options.ignoreStringLiterals === true; | ||
const sourceCode = context.sourceCode; | ||
let avoidEscape = options && typeof options === "object" && options.avoidEscape === true; | ||
if (options === AVOID_ESCAPE) | ||
let avoidEscape = false; | ||
let ignoreStringLiterals = false; | ||
let allowTemplateLiteralsAlways = false; | ||
let allowTemplateLiteralsToAvoidEscape = false; | ||
if (typeof options === "object") { | ||
avoidEscape = options.avoidEscape === true; | ||
ignoreStringLiterals = options.ignoreStringLiterals === true; | ||
if (typeof options.allowTemplateLiterals === "string") { | ||
allowTemplateLiteralsAlways = options.allowTemplateLiterals === "always"; | ||
allowTemplateLiteralsToAvoidEscape = allowTemplateLiteralsAlways || options.allowTemplateLiterals === "avoidEscape"; | ||
} else if (typeof options.allowTemplateLiterals === "boolean") { | ||
allowTemplateLiteralsAlways = options.allowTemplateLiterals === true; | ||
allowTemplateLiteralsToAvoidEscape = options.allowTemplateLiterals === true; | ||
} | ||
} else if (options === AVOID_ESCAPE) { | ||
avoidEscape = true; | ||
} | ||
function isJSXLiteral(node) { | ||
@@ -198,6 +218,6 @@ if (!node.parent) | ||
TemplateLiteral(node) { | ||
if (allowTemplateLiterals || quoteOption === "backtick" || isUsingFeatureOfTemplateLiteral(node)) { | ||
if (allowTemplateLiteralsAlways || quoteOption === "backtick" || isUsingFeatureOfTemplateLiteral(node)) { | ||
return; | ||
} | ||
if (allowTemplateLiterals && avoidEscape && sourceCode.getText(node).includes(settings.quote)) | ||
if (allowTemplateLiteralsToAvoidEscape && avoidEscape && sourceCode.getText(node).includes(settings.quote)) | ||
return; | ||
@@ -239,3 +259,3 @@ context.report({ | ||
{ | ||
allowTemplateLiterals: false, | ||
allowTemplateLiterals: "never", | ||
avoidEscape: false, | ||
@@ -242,0 +262,0 @@ ignoreStringLiterals: false |
@@ -11,4 +11,4 @@ 'use strict'; | ||
const globals = { | ||
...options?.before !== void 0 ? { before: options.before } : {}, | ||
...options?.after !== void 0 ? { after: options.after } : {} | ||
...options?.before !== undefined ? { before: options.before } : {}, | ||
...options?.after !== undefined ? { after: options.after } : {} | ||
}; | ||
@@ -15,0 +15,0 @@ const override = options?.overrides ?? {}; |
@@ -47,2 +47,30 @@ 'use strict'; | ||
const params = node.params; | ||
const openToken = sourceCode.getTokenBefore(params[0]); | ||
const firstToken = openToken ? sourceCode.getTokenAfter(openToken) : null; | ||
const closeToken = sourceCode.getTokenAfter(params[params.length - 1]); | ||
const lastToken = closeToken ? sourceCode.getTokenBefore(closeToken) : null; | ||
if (openToken && firstToken) { | ||
const textBetween = sourceCode.text.slice(openToken.range[1], firstToken.range[0]); | ||
if (/\s/.test(textBetween) && !/^[\r\n]/.test(textBetween)) { | ||
context.report({ | ||
node, | ||
messageId: "genericSpacingMismatch", | ||
*fix(fixer) { | ||
yield fixer.replaceTextRange([openToken.range[1], firstToken.range[0]], ""); | ||
} | ||
}); | ||
} | ||
} | ||
if (closeToken && lastToken) { | ||
const textBetween = sourceCode.text.slice(lastToken.range[1], closeToken.range[0]); | ||
if (/\s/.test(textBetween) && !/^[\r\n]/.test(textBetween)) { | ||
context.report({ | ||
node, | ||
messageId: "genericSpacingMismatch", | ||
*fix(fixer) { | ||
yield fixer.replaceTextRange([lastToken.range[1], closeToken.range[0]], ""); | ||
} | ||
}); | ||
} | ||
} | ||
for (let i = 1; i < params.length; i++) { | ||
@@ -49,0 +77,0 @@ const prev = params[i - 1]; |
{ | ||
"name": "@stylistic/eslint-plugin", | ||
"type": "commonjs", | ||
"version": "2.13.0", | ||
"version": "3.0.0", | ||
"author": "Anthony Fu <anthonyfu117@hotmail.com>", | ||
@@ -137,3 +137,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@typescript-eslint/utils": "^8.13.0", | ||
"@typescript-eslint/utils": "8.13.0", | ||
"eslint-visitor-keys": "^4.2.0", | ||
@@ -140,0 +140,0 @@ "espree": "^10.3.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
814102
23055
+ Added@eslint/config-array@0.19.1(transitive)
+ Added@eslint/object-schema@2.1.5(transitive)
+ Added@typescript-eslint/scope-manager@8.13.0(transitive)
+ Added@typescript-eslint/types@8.13.0(transitive)
+ Added@typescript-eslint/typescript-estree@8.13.0(transitive)
+ Added@typescript-eslint/utils@8.13.0(transitive)
+ Added@typescript-eslint/visitor-keys@8.13.0(transitive)
+ Addedfastq@1.18.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedts-api-utils@1.4.3(transitive)
- Removed@eslint/config-array@0.19.2(transitive)
- Removed@eslint/object-schema@2.1.6(transitive)
- Removed@typescript-eslint/scope-manager@8.22.0(transitive)
- Removed@typescript-eslint/types@8.22.0(transitive)
- Removed@typescript-eslint/typescript-estree@8.22.0(transitive)
- Removed@typescript-eslint/utils@8.22.0(transitive)
- Removed@typescript-eslint/visitor-keys@8.22.0(transitive)
- Removedfastq@1.19.0(transitive)
- Removedsemver@7.7.0(transitive)
- Removedts-api-utils@2.0.1(transitive)