-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(deps)!: bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0 #1235
Merged
ybiquitous
merged 3 commits into
main
from
dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.1.0
Jul 20, 2023
Merged
feat(deps)!: bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0 #1235
ybiquitous
merged 3 commits into
main
from
dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.1.0
Jul 20, 2023
Conversation
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
dependabot
bot
added
dependencies
Pull requests that update a dependency file
javascript
Pull requests that update Javascript code
labels
Jul 20, 2023
Diff between @typescript-eslint/eslint-plugin 5.60.1 and 6.1.0diff --git a/dist/rules/adjacent-overload-signatures.js b/dist/rules/adjacent-overload-signatures.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/adjacent-overload-signatures.js
+++ b/dist/rules/adjacent-overload-signatures.js
@@ -32,5 +32,5 @@
docs: {
description: 'Require that function overload signatures be consecutive',
- recommended: 'error',
+ recommended: 'stylistic',
},
schema: [],
@@ -48,5 +48,4 @@
*/
function getMemberMethod(member) {
- var _a, _b;
if (!member) {
return null;
@@ -65,5 +64,5 @@
case utils_1.AST_NODE_TYPES.TSDeclareFunction:
case utils_1.AST_NODE_TYPES.FunctionDeclaration: {
- const name = (_b = (_a = member.id) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null;
+ const name = member.id?.name ?? null;
if (name == null) {
return null;
@@ -77,5 +76,9 @@
}
case utils_1.AST_NODE_TYPES.TSMethodSignature:
- return Object.assign(Object.assign({}, util.getNameFromMember(member, sourceCode)), { static: isStatic, callSignature: false });
+ return {
+ ...util.getNameFromMember(member, sourceCode),
+ static: isStatic,
+ callSignature: false,
+ };
case utils_1.AST_NODE_TYPES.TSCallSignatureDeclaration:
return {
@@ -93,5 +96,9 @@
};
case utils_1.AST_NODE_TYPES.MethodDefinition:
- return Object.assign(Object.assign({}, util.getNameFromMember(member, sourceCode)), { static: isStatic, callSignature: false });
+ return {
+ ...util.getNameFromMember(member, sourceCode),
+ static: isStatic,
+ callSignature: false,
+ };
}
return null;
diff --git a/dist/configs/all.js b/dist/configs/all.js
index v5.60.1..v6.1.0 100644
--- a/dist/configs/all.js
+++ b/dist/configs/all.js
@@ -2,5 +2,8 @@
// THIS CODE WAS AUTOMATICALLY GENERATED
// DO NOT EDIT THIS CODE BY HAND
-// YOU CAN REGENERATE IT USING yarn generate:configs
+// SEE https://typescript-eslint.io/linting/configs
+//
+// For developers working in the typescript-eslint monorepo:
+// You can regenerate it using `yarn generate:configs`
module.exports = {
extends: ['./configs/base', './configs/eslint-recommended'],
@@ -106,5 +109,4 @@
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',
- '@typescript-eslint/no-type-alias': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
diff --git a/dist/rules/array-type.js b/dist/rules/array-type.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/array-type.js
+++ b/dist/rules/array-type.js
@@ -53,13 +53,13 @@
node.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
node.typeName.name === 'Array') {
- if (!node.typeParameters) {
+ if (!node.typeArguments) {
return true;
}
- if (node.typeParameters.params.length === 1) {
- return isSimpleType(node.typeParameters.params[0]);
+ if (node.typeArguments.params.length === 1) {
+ return isSimpleType(node.typeArguments.params[0]);
}
}
else {
- if (node.typeParameters) {
+ if (node.typeArguments) {
return false;
}
@@ -98,5 +98,5 @@
docs: {
description: 'Require consistently using either `T[]` or `Array<T>` for arrays',
- recommended: 'strict',
+ recommended: 'stylistic',
},
fixable: 'code',
@@ -107,27 +107,26 @@
errorStringGenericSimple: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.",
},
- schema: {
- $defs: {
- arrayOption: {
- enum: ['array', 'generic', 'array-simple'],
+ schema: [
+ {
+ $defs: {
+ arrayOption: {
+ type: 'string',
+ enum: ['array', 'generic', 'array-simple'],
+ },
},
- },
- prefixItems: [
- {
- properties: {
- default: {
- $ref: '#/$defs/arrayOption',
- description: 'The array type expected for mutable cases...',
- },
- readonly: {
- $ref: '#/$defs/arrayOption',
- description: 'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
- },
+ additionalProperties: false,
+ properties: {
+ default: {
+ $ref: '#/items/0/$defs/arrayOption',
+ description: 'The array type expected for mutable cases.',
},
- type: 'object',
+ readonly: {
+ $ref: '#/items/0/$defs/arrayOption',
+ description: 'The array type expected for readonly cases. If omitted, the value for `default` will be used.',
+ },
},
- ],
- type: 'array',
- },
+ type: 'object',
+ },
+ ],
},
defaultOptions: [
@@ -137,8 +136,7 @@
],
create(context, [options]) {
- var _a;
const sourceCode = context.getSourceCode();
const defaultOption = options.default;
- const readonlyOption = (_a = options.readonly) !== null && _a !== void 0 ? _a : defaultOption;
+ const readonlyOption = options.readonly ?? defaultOption;
/**
* @param node the node to be evaluated.
@@ -152,6 +150,5 @@
return {
TSArrayType(node) {
- const isReadonly = node.parent &&
- node.parent.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
+ const isReadonly = node.parent.type === utils_1.AST_NODE_TYPES.TSTypeOperator &&
node.parent.operator === 'readonly';
const currentOption = isReadonly ? readonlyOption : defaultOption;
@@ -183,5 +180,4 @@
},
TSTypeReference(node) {
- var _a, _b;
if (node.typeName.type !== utils_1.AST_NODE_TYPES.Identifier ||
!(node.typeName.name === 'Array' ||
@@ -197,5 +193,5 @@
}
const readonlyPrefix = isReadonlyArrayType ? 'readonly ' : '';
- const typeParams = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params;
+ const typeParams = node.typeArguments?.params;
const messageId = currentOption === 'array'
? 'errorStringArray'
@@ -224,5 +220,5 @@
const typeParens = typeNeedsParentheses(type);
const parentParens = readonlyPrefix &&
- ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.TSArrayType &&
+ node.parent?.type === utils_1.AST_NODE_TYPES.TSArrayType &&
!util.isParenthesized(node.parent.elementType, sourceCode);
const start = `${parentParens ? '(' : ''}${readonlyPrefix}${typeParens ? '(' : ''}`;
diff --git a/dist/util/astUtils.js b/dist/util/astUtils.js
index v5.60.1..v6.1.0 100644
--- a/dist/util/astUtils.js
+++ b/dist/util/astUtils.js
@@ -31,5 +31,5 @@
const escapeRegExp_1 = require("./escapeRegExp");
// deeply re-export, for convenience
-__exportStar(require("@typescript-eslint/utils/dist/ast-utils"), exports);
+__exportStar(require("@typescript-eslint/utils/ast-utils"), exports);
// The following is copied from `eslint`'s source code since it doesn't exist in eslint@5.
// https://github.com/eslint/eslint/blob/145aec1ab9052fbca96a44d04927c595951b1536/lib/rules/utils/ast-utils.js#L1751-L1779
diff --git a/dist/rules/await-thenable.js b/dist/rules/await-thenable.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/await-thenable.js
+++ b/dist/rules/await-thenable.js
@@ -24,5 +24,5 @@
};
Object.defineProperty(exports, "__esModule", { value: true });
-const tsutils = __importStar(require("tsutils"));
+const tsutils = __importStar(require("ts-api-utils"));
const util = __importStar(require("../util"));
exports.default = util.createRule({
@@ -31,5 +31,5 @@
docs: {
description: 'Disallow awaiting a value that is not a Thenable',
- recommended: 'error',
+ recommended: 'recommended',
requiresTypeChecking: true,
},
@@ -42,13 +42,14 @@
defaultOptions: [],
create(context) {
- const parserServices = util.getParserServices(context);
- const checker = parserServices.program.getTypeChecker();
+ const services = util.getParserServices(context);
+ const checker = services.program.getTypeChecker();
return {
AwaitExpression(node) {
- const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);
- const type = checker.getTypeAtLocation(originalNode.expression);
- if (!util.isTypeAnyType(type) &&
- !util.isTypeUnknownType(type) &&
- !tsutils.isThenableType(checker, originalNode.expression, type)) {
+ const type = services.getTypeAtLocation(node.argument);
+ if (util.isTypeAnyType(type) || util.isTypeUnknownType(type)) {
+ return;
+ }
+ const originalNode = services.esTreeNodeToTSNodeMap.get(node);
+ if (!tsutils.isThenableType(checker, originalNode.expression, type)) {
context.report({
messageId: 'await',
diff --git a/dist/rules/ban-ts-comment.js b/dist/rules/ban-ts-comment.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/ban-ts-comment.js
+++ b/dist/rules/ban-ts-comment.js
@@ -34,5 +34,5 @@
docs: {
description: 'Disallow `@ts-<directive>` comments or require descriptions after directives',
- recommended: 'error',
+ recommended: 'recommended',
},
messages: {
@@ -41,43 +41,41 @@
tsDirectiveCommentDescriptionNotMatchPattern: 'The description for the "@ts-{{directive}}" directive must match the {{format}} format.',
},
- schema: {
- $defs: {
- directiveConfigSchema: {
- oneOf: [
- {
- type: 'boolean',
- default: true,
- },
- {
- enum: ['allow-with-description'],
- },
- {
- type: 'object',
- properties: {
- descriptionFormat: { type: 'string' },
+ schema: [
+ {
+ $defs: {
+ directiveConfigSchema: {
+ oneOf: [
+ {
+ type: 'boolean',
+ default: true,
},
- },
- ],
+ {
+ type: 'string',
+ enum: ['allow-with-description'],
+ },
+ {
+ type: 'object',
+ additionalProperties: false,
+ properties: {
+ descriptionFormat: { type: 'string' },
+ },
+ },
+ ],
+ },
},
- },
- prefixItems: [
- {
- properties: {
- 'ts-expect-error': {
- $ref: '#/$defs/directiveConfigSchema',
- },
- 'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' },
- 'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' },
- 'ts-check': { $ref: '#/$defs/directiveConfigSchema' },
- minimumDescriptionLength: {
- type: 'number',
- default: exports.defaultMinimumDescriptionLength,
- },
+ properties: {
+ 'ts-expect-error': { $ref: '#/items/0/$defs/directiveConfigSchema' },
+ 'ts-ignore': { $ref: '#/items/0/$defs/directiveConfigSchema' },
+ 'ts-nocheck': { $ref: '#/items/0/$defs/directiveConfigSchema' },
+ 'ts-check': { $ref: '#/items/0/$defs/directiveConfigSchema' },
+ minimumDescriptionLength: {
+ type: 'number',
+ default: exports.defaultMinimumDescriptionLength,
},
- additionalProperties: false,
},
- ],
- type: 'array',
- },
+ type: 'object',
+ additionalProperties: false,
+ },
+ ],
},
defaultOptions: [
diff --git a/dist/rules/ban-tslint-comment.js b/dist/rules/ban-tslint-comment.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/ban-tslint-comment.js
+++ b/dist/rules/ban-tslint-comment.js
@@ -38,5 +38,5 @@
docs: {
description: 'Disallow `// tslint:<rule-flag>` comments',
- recommended: 'strict',
+ recommended: 'stylistic',
},
messages: {
diff --git a/dist/rules/ban-types.js b/dist/rules/ban-types.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/ban-types.js
+++ b/dist/rules/ban-types.js
@@ -34,5 +34,5 @@
}
function getCustomMessage(bannedType) {
- if (bannedType == null) {
+ if (bannedType == null || bannedType === true) {
return '';
}
@@ -119,5 +119,5 @@
docs: {
description: 'Disallow certain types',
- recommended: 'error',
+ recommended: 'recommended',
},
fixable: 'code',
@@ -129,4 +129,49 @@
schema: [
{
+ $defs: {
+ banConfig: {
+ oneOf: [
+ {
+ type: 'null',
+ description: 'Bans the type with the default message',
+ },
+ {
+ type: 'boolean',
+ enum: [false],
+ description: 'Un-bans the type (useful when paired with `extendDefaults`)',
+ },
+ {
+ type: 'boolean',
+ enum: [true],
+ description: 'Bans the type with the default message',
+ },
+ {
+ type: 'string',
+ description: 'Bans the type with a custom message',
+ },
+ {
+ type: 'object',
+ description: 'Bans a type',
+ properties: {
+ message: {
+ type: 'string',
+ description: 'Custom error message',
+ },
+ fixWith: {
+ type: 'string',
+ description: 'Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.',
+ },
+ suggest: {
+ type: 'array',
+ items: { type: 'string' },
+ description: 'Types to suggest replacing with.',
+ additionalItems: false,
+ },
+ },
+ additionalProperties: false,
+ },
+ ],
+ },
+ },
type: 'object',
properties: {
@@ -134,21 +179,5 @@
type: 'object',
additionalProperties: {
- oneOf: [
- { type: 'null' },
- { type: 'boolean' },
- { type: 'string' },
- {
- type: 'object',
- properties: {
- message: { type: 'string' },
- fixWith: { type: 'string' },
- suggest: {
- type: 'array',
- items: { type: 'string' },
- },
- },
- additionalProperties: false,
- },
- ],
+ $ref: '#/items/0/$defs/banConfig',
},
},
@@ -163,7 +192,6 @@
defaultOptions: [{}],
create(context, [options]) {
- var _a, _b;
- const extendDefaults = (_a = options.extendDefaults) !== null && _a !== void 0 ? _a : true;
- const customTypes = (_b = options.types) !== null && _b !== void 0 ? _b : {};
+ const extendDefaults = options.extendDefaults ?? true;
+ const customTypes = options.types ?? {};
const types = Object.assign({}, extendDefaults ? defaultTypes : {}, customTypes);
const bannedTypes = new Map(Object.entries(types).map(([type, data]) => [removeSpaces(type), data]));
@@ -188,5 +216,5 @@
? (fixer) => fixer.replaceText(typeNode, fixWith)
: null,
- suggest: suggest === null || suggest === void 0 ? void 0 : suggest.map(replacement => ({
+ suggest: suggest?.map(replacement => ({
messageId: 'bannedTypeReplacement',
data: {
@@ -204,5 +232,7 @@
return acc;
}, {});
- return Object.assign(Object.assign({}, keywordSelectors), { TSTypeLiteral(node) {
+ return {
+ ...keywordSelectors,
+ TSTypeLiteral(node) {
if (node.members.length) {
return;
@@ -217,8 +247,15 @@
TSTypeReference(node) {
checkBannedTypes(node.typeName);
- if (node.typeParameters) {
+ if (node.typeArguments) {
checkBannedTypes(node);
}
- } });
+ },
+ TSInterfaceHeritage(node) {
+ checkBannedTypes(node);
+ },
+ TSClassImplements(node) {
+ checkBannedTypes(node);
+ },
+ };
},
});
diff --git a/dist/configs/base.js b/dist/configs/base.js
index v5.60.1..v6.1.0 100644
--- a/dist/configs/base.js
+++ b/dist/configs/base.js
@@ -2,5 +2,8 @@
// THIS CODE WAS AUTOMATICALLY GENERATED
// DO NOT EDIT THIS CODE BY HAND
-// YOU CAN REGENERATE IT USING yarn generate:configs
+// SEE https://typescript-eslint.io/linting/configs
+//
+// For developers working in the typescript-eslint monorepo:
+// You can regenerate it using `yarn generate:configs`
module.exports = {
parser: '@typescript-eslint/parser',
diff --git a/dist/rules/block-spacing.js b/dist/rules/block-spacing.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/block-spacing.js
+++ b/dist/rules/block-spacing.js
@@ -34,5 +34,4 @@
docs: {
description: 'Disallow or enforce spaces inside of blocks after opening block and before closing block',
- recommended: false,
extendsBaseRule: true,
},
@@ -148,10 +147,14 @@
}
}
- return Object.assign(Object.assign({}, baseRules), {
+ return {
+ ...baseRules,
// This code worked "out of the box" for interface and type literal
// Enums were very close to match as well, the only reason they are not is that was that enums don't have a body node in the parser
// So the opening brace punctuator starts in the middle of the node - `getFirstToken` in
// the base rule did not filter for the first opening brace punctuator
- TSInterfaceBody: baseRules.BlockStatement, TSTypeLiteral: baseRules.BlockStatement, TSEnumDeclaration: checkSpacingInsideBraces });
+ TSInterfaceBody: baseRules.BlockStatement,
+ TSTypeLiteral: baseRules.BlockStatement,
+ TSEnumDeclaration: checkSpacingInsideBraces,
+ };
},
});
diff --git a/dist/rules/brace-style.js b/dist/rules/brace-style.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/brace-style.js
+++ b/dist/rules/brace-style.js
@@ -10,5 +10,4 @@
docs: {
description: 'Enforce consistent brace style for blocks',
- recommended: false,
extendsBaseRule: true,
},
@@ -80,5 +79,7 @@
}
}
- return Object.assign(Object.assign({}, rules), { 'TSInterfaceBody, TSModuleBlock'(node) {
+ return {
+ ...rules,
+ 'TSInterfaceBody, TSModuleBlock'(node) {
const openingCurly = sourceCode.getFirstToken(node);
const closingCurly = sourceCode.getLastToken(node);
@@ -89,5 +90,6 @@
const openingCurly = sourceCode.getTokenBefore(node.members.length ? node.members[0] : closingCurly);
validateCurlyPair(openingCurly, closingCurly);
- } });
+ },
+ };
},
});
diff --git a/dist/rules/class-literal-property-style.js b/dist/rules/class-literal-property-style.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/class-literal-property-style.js
+++ b/dist/rules/class-literal-property-style.js
@@ -26,8 +26,5 @@
const utils_1 = require("@typescript-eslint/utils");
const util = __importStar(require("../util"));
-const printNodeModifiers = (node, final) => {
- var _a;
- return `${(_a = node.accessibility) !== null && _a !== void 0 ? _a : ''}${node.static ? ' static' : ''} ${final} `.trimStart();
-};
+const printNodeModifiers = (node, final) => `${node.accessibility ?? ''}${node.static ? ' static' : ''} ${final} `.trimStart();
const isSupportedLiteral = (node) => {
if (node.type === utils_1.AST_NODE_TYPES.Literal) {
@@ -46,68 +43,88 @@
docs: {
description: 'Enforce that literals on classes are exposed in a consistent style',
- recommended: 'strict',
+ recommended: 'stylistic',
},
- fixable: 'code',
+ hasSuggestions: true,
messages: {
preferFieldStyle: 'Literals should be exposed using readonly fields.',
+ preferFieldStyleSuggestion: 'Replace the literals with readonly fields.',
preferGetterStyle: 'Literals should be exposed using getters.',
+ preferGetterStyleSuggestion: 'Replace the literals with getters.',
},
- schema: [{ enum: ['fields', 'getters'] }],
+ schema: [
+ {
+ type: 'string',
+ enum: ['fields', 'getters'],
+ },
+ ],
},
defaultOptions: ['fields'],
create(context, [style]) {
- return Object.assign(Object.assign({}, (style === 'fields' && {
- MethodDefinition(node) {
- if (node.kind !== 'get' ||
- !node.value.body ||
- !node.value.body.body.length) {
- return;
- }
- const [statement] = node.value.body.body;
- if (statement.type !== utils_1.AST_NODE_TYPES.ReturnStatement) {
- return;
- }
- const { argument } = statement;
- if (!argument || !isSupportedLiteral(argument)) {
- return;
- }
- context.report({
- node: node.key,
- messageId: 'preferFieldStyle',
- fix(fixer) {
- const sourceCode = context.getSourceCode();
- const name = sourceCode.getText(node.key);
- let text = '';
- text += printNodeModifiers(node, 'readonly');
- text += node.computed ? `[${name}]` : name;
- text += ` = ${sourceCode.getText(argument)};`;
- return fixer.replaceText(node, text);
- },
- });
- },
- })), (style === 'getters' && {
- PropertyDefinition(node) {
- if (!node.readonly || node.declare) {
- return;
- }
- const { value } = node;
- if (!value || !isSupportedLiteral(value)) {
- return;
- }
- context.report({
- node: node.key,
- messageId: 'preferGetterStyle',
- fix(fixer) {
- const sourceCode = context.getSourceCode();
- const name = sourceCode.getText(node.key);
- let text = '';
- text += printNodeModifiers(node, 'get');
- text += node.computed ? `[${name}]` : name;
- text += `() { return ${sourceCode.getText(value)}; }`;
- return fixer.replaceText(node, text);
- },
- });
- },
- }));
+ return {
+ ...(style === 'fields' && {
+ MethodDefinition(node) {
+ if (node.kind !== 'get' ||
+ !node.value.body ||
+ node.value.body.body.length === 0) {
+ return;
+ }
+ const [statement] = node.value.body.body;
+ if (statement.type !== utils_1.AST_NODE_TYPES.ReturnStatement) {
+ return;
+ }
+ const { argument } = statement;
+ if (!argument || !isSupportedLiteral(argument)) {
+ return;
+ }
+ context.report({
+ node: node.key,
+ messageId: 'preferFieldStyle',
+ suggest: [
+ {
+ messageId: 'preferFieldStyleSuggestion',
+ fix(fixer) {
+ const sourceCode = context.getSourceCode();
+ const name = sourceCode.getText(node.key);
+ let text = '';
+ text += printNodeModifiers(node, 'readonly');
+ text += node.computed ? `[${name}]` : name;
+ text += ` = ${sourceCode.getText(argument)};`;
+ return fixer.replaceText(node, text);
+ },
+ },
+ ],
+ });
+ },
+ }),
+ ...(style === 'getters' && {
+ PropertyDefinition(node) {
+ if (!node.readonly || node.declare) {
+ return;
+ }
+ const { value } = node;
+ if (!value || !isSupportedLiteral(value)) {
+ return;
+ }
+ context.report({
+ node: node.key,
+ messageId: 'preferGetterStyle',
+ suggest: [
+ {
+ messageId: 'preferGetterStyleSuggestion',
+ fix(fixer) {
+ const sourceCode = context.getSourceCode();
+ const name = sourceCode.getText(node.key);
+ let text = '';
+ text += printNodeModifiers(node, 'get');
+ text += node.computed ? `[${name}]` : name;
+ text += `() { return ${sourceCode.getText(value)}; }`;
+ return fixer.replaceText(node, text);
+ },
+ },
+ ],
+ });
+ },
+ }),
+ };
},
});
diff --git a/dist/util/collectUnusedVariables.js b/dist/util/collectUnusedVariables.js
index v5.60.1..v6.1.0 100644
--- a/dist/util/collectUnusedVariables.js
+++ b/dist/util/collectUnusedVariables.js
@@ -15,7 +15,6 @@
exports.collectUnusedVariables = void 0;
const scope_manager_1 = require("@typescript-eslint/scope-manager");
-const Visitor_1 = require("@typescript-eslint/scope-manager/dist/referencer/Visitor");
const utils_1 = require("@typescript-eslint/utils");
-class UnusedVarsVisitor extends Visitor_1.Visitor {
+class UnusedVarsVisitor extends scope_manager_1.Visitor {
// readonly #unusedVariables = new Set<TSESLint.Scope.Variable>();
constructor(context) {
@@ -86,5 +85,5 @@
const scope = __classPrivateFieldGet(this, _UnusedVarsVisitor_scopeManager, "f").acquire(node, inner);
if (scope) {
- if (scope.type === 'function-expression-name') {
+ if (scope.type === scope_manager_1.ScopeType.functionExpressionName) {
return scope.childScopes[0];
}
@@ -135,5 +134,5 @@
// skip implicit "arguments" variable
const variable = scope.set.get('arguments');
- if ((variable === null || variable === void 0 ? void 0 : variable.defs.length) === 0) {
+ if (variable?.defs.length === 0) {
this.markVariableAsUsed(variable);
}
@@ -289,5 +288,4 @@
*/
function isMergableExported(variable) {
- var _a, _b;
// If all of the merged things are of the same type, TS will error if not all of them are exported - so we only need to find one
for (const def of variable.defs) {
@@ -299,6 +297,6 @@
}
if ((MERGABLE_TYPES.has(def.node.type) &&
- ((_a = def.node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) ||
- ((_b = def.node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
+ def.node.parent?.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) ||
+ def.node.parent?.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
return true;
}
@@ -312,6 +310,5 @@
*/
function isExported(variable) {
- const definition = variable.defs[0];
- if (definition) {
+ return variable.defs.some(definition => {
let node = definition.node;
if (node.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
@@ -322,6 +319,5 @@
}
return node.parent.type.indexOf('Export') === 0;
- }
- return false;
+ });
}
/**
@@ -339,5 +335,4 @@
const functionDefinitions = new Set();
variable.defs.forEach(def => {
- var _a, _b;
// FunctionDeclarations
if (def.type === utils_1.TSESLint.Scope.DefinitionType.FunctionName) {
@@ -346,6 +341,6 @@
// FunctionExpressions
if (def.type === utils_1.TSESLint.Scope.DefinitionType.Variable &&
- (((_a = def.node.init) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.FunctionExpression ||
- ((_b = def.node.init) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
+ (def.node.init?.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
+ def.node.init?.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression)) {
functionDefinitions.add(def.node.init);
}
diff --git a/dist/rules/comma-dangle.js b/dist/rules/comma-dangle.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/comma-dangle.js
+++ b/dist/rules/comma-dangle.js
@@ -36,5 +36,4 @@
const DEFAULT_OPTION_VALUE = 'never';
function normalizeOptions(options) {
- var _a, _b, _c;
if (typeof options === 'string') {
return {
@@ -45,7 +44,7 @@
}
return {
- enums: (_a = options.enums) !== null && _a !== void 0 ? _a : DEFAULT_OPTION_VALUE,
- generics: (_b = options.generics) !== null && _b !== void 0 ? _b : DEFAULT_OPTION_VALUE,
- tuples: (_c = options.tuples) !== null && _c !== void 0 ? _c : DEFAULT_OPTION_VALUE,
+ enums: options.enums ?? DEFAULT_OPTION_VALUE,
+ generics: options.generics ?? DEFAULT_OPTION_VALUE,
+ tuples: options.tuples ?? DEFAULT_OPTION_VALUE,
};
}
@@ -56,5 +55,4 @@
docs: {
description: 'Require or disallow trailing commas',
- recommended: false,
extendsBaseRule: true,
},
@@ -62,7 +60,9 @@
$defs: {
value: {
+ type: 'string',
enum: OPTION_VALUE_SCHEME,
},
valueWithIgnore: {
+ type: 'string',
enum: [...OPTION_VALUE_SCHEME, 'ignore'],
},
@@ -92,5 +92,5 @@
},
],
- additionalProperties: false,
+ additionalItems: false,
},
fixable: 'code',
@@ -108,9 +108,10 @@
'only-multiline': allowCommaIfMultiline,
never: forbidComma,
+ // https://github.com/typescript-eslint/typescript-eslint/issues/7220
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-empty-function
ignore: () => { },
};
function last(nodes) {
- var _a;
- return (_a = nodes[nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
+ return nodes[nodes.length - 1] ?? null;
}
function getLastItem(node) {
@@ -134,5 +135,5 @@
const last = getLastItem(node);
const lastToken = sourceCode.getLastToken(node);
- return (last === null || last === void 0 ? void 0 : last.loc.end.line) !== (lastToken === null || lastToken === void 0 ? void 0 : lastToken.loc.end.line);
+ return last?.loc.end.line !== lastToken?.loc.end.line;
}
function forbidComma(node) {
@@ -175,5 +176,10 @@
}
}
- return Object.assign(Object.assign({}, rules), { TSEnumDeclaration: predicate[normalizedOptions.enums], TSTypeParameterDeclaration: predicate[normalizedOptions.generics], TSTupleType: predicate[normalizedOptions.tuples] });
+ return {
+ ...rules,
+ TSEnumDeclaration: predicate[normalizedOptions.enums],
+ TSTypeParameterDeclaration: predicate[normalizedOptions.generics],
+ TSTupleType: predicate[normalizedOptions.tuples],
+ };
},
});
diff --git a/dist/rules/comma-spacing.js b/dist/rules/comma-spacing.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/comma-spacing.js
+++ b/dist/rules/comma-spacing.js
@@ -9,5 +9,4 @@
docs: {
description: 'Enforce consistent spacing before and after commas',
- recommended: false,
extendsBaseRule: true,
},
@@ -103,4 +102,9 @@
return;
}
+ if (spaceAfter &&
+ nextToken &&
+ ((0, util_1.isClosingBraceToken)(nextToken) || (0, util_1.isClosingBracketToken)(nextToken))) {
+ return;
+ }
if (!spaceAfter && nextToken && nextToken.type === utils_1.AST_TOKEN_TYPES.Line) {
return;
diff --git a/dist/rules/consistent-generic-constructors.js b/dist/rules/consistent-generic-constructors.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-generic-constructors.js
+++ b/dist/rules/consistent-generic-constructors.js
@@ -9,5 +9,5 @@
docs: {
description: 'Enforce specifying generic type arguments on type annotation or constructor name of a constructor call',
- recommended: 'strict',
+ recommended: 'stylistic',
},
messages: {
@@ -18,4 +18,5 @@
schema: [
{
+ type: 'string',
enum: ['type-annotation', 'constructor'],
},
@@ -27,5 +28,4 @@
return {
'VariableDeclarator,PropertyDefinition,:matches(FunctionDeclaration,FunctionExpression) > AssignmentPattern'(node) {
- var _a, _b;
function getLHSRHS() {
switch (node.type) {
@@ -41,5 +41,5 @@
}
const [lhsName, rhs] = getLHSRHS();
- const lhs = (_a = lhsName.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation;
+ const lhs = lhsName.typeAnnotation?.typeAnnotation;
if (!rhs ||
rhs.type !== utils_1.AST_NODE_TYPES.NewExpression ||
@@ -54,7 +54,7 @@
}
if (mode === 'type-annotation') {
- if (!lhs && rhs.typeParameters) {
- const { typeParameters, callee } = rhs;
- const typeAnnotation = sourceCode.getText(callee) + sourceCode.getText(typeParameters);
+ if (!lhs && rhs.typeArguments) {
+ const { typeArguments, callee } = rhs;
+ const typeAnnotation = sourceCode.getText(callee) + sourceCode.getText(typeArguments);
context.report({
node,
@@ -73,5 +73,5 @@
}
return [
- fixer.remove(typeParameters),
+ fixer.remove(typeArguments),
fixer.insertTextAfter(getIDToAttachAnnotation(), ': ' + typeAnnotation),
];
@@ -82,9 +82,9 @@
}
if (mode === 'constructor') {
- if ((lhs === null || lhs === void 0 ? void 0 : lhs.typeParameters) && !rhs.typeParameters) {
- const hasParens = ((_b = sourceCode.getTokenAfter(rhs.callee)) === null || _b === void 0 ? void 0 : _b.value) === '(';
+ if (lhs?.typeArguments && !rhs.typeArguments) {
+ const hasParens = sourceCode.getTokenAfter(rhs.callee)?.value === '(';
const extraComments = new Set(sourceCode.getCommentsInside(lhs.parent));
sourceCode
- .getCommentsInside(lhs.typeParameters)
+ .getCommentsInside(lhs.typeArguments)
.forEach(c => extraComments.delete(c));
context.report({
@@ -96,5 +96,5 @@
yield fixer.insertTextAfter(rhs.callee, sourceCode.getText(comment));
}
- yield fixer.insertTextAfter(rhs.callee, sourceCode.getText(lhs.typeParameters));
+ yield fixer.insertTextAfter(rhs.callee, sourceCode.getText(lhs.typeArguments));
if (!hasParens) {
yield fixer.insertTextAfter(rhs.callee, '()');
diff --git a/dist/rules/consistent-indexed-object-style.js b/dist/rules/consistent-indexed-object-style.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-indexed-object-style.js
+++ b/dist/rules/consistent-indexed-object-style.js
@@ -9,5 +9,5 @@
docs: {
description: 'Require or disallow the `Record` type',
- recommended: 'strict',
+ recommended: 'stylistic',
},
messages: {
@@ -18,4 +18,5 @@
schema: [
{
+ type: 'string',
enum: ['record', 'index-signature'],
},
@@ -75,42 +76,45 @@
});
}
- return Object.assign(Object.assign({}, (mode === 'index-signature' && {
- TSTypeReference(node) {
- var _a;
- const typeName = node.typeName;
- if (typeName.type !== utils_1.AST_NODE_TYPES.Identifier) {
- return;
- }
- if (typeName.name !== 'Record') {
- return;
- }
- const params = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params;
- if ((params === null || params === void 0 ? void 0 : params.length) !== 2) {
- return;
- }
- context.report({
- node,
- messageId: 'preferIndexSignature',
- fix(fixer) {
- const key = sourceCode.getText(params[0]);
- const type = sourceCode.getText(params[1]);
- return fixer.replaceText(node, `{ [key: ${key}]: ${type} }`);
- },
- });
- },
- })), (mode === 'record' && {
- TSTypeLiteral(node) {
- const parent = findParentDeclaration(node);
- checkMembers(node.members, node, parent === null || parent === void 0 ? void 0 : parent.id, '', '');
- },
- TSInterfaceDeclaration(node) {
- var _a, _b, _c, _d;
- let genericTypes = '';
- if (((_b = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : []).length > 0) {
- genericTypes = `<${(_c = node.typeParameters) === null || _c === void 0 ? void 0 : _c.params.map(p => sourceCode.getText(p)).join(', ')}>`;
- }
- checkMembers(node.body.body, node, node.id, `type ${node.id.name}${genericTypes} = `, ';', !((_d = node.extends) === null || _d === void 0 ? void 0 : _d.length));
- },
- }));
+ return {
+ ...(mode === 'index-signature' && {
+ TSTypeReference(node) {
+ const typeName = node.typeName;
+ if (typeName.type !== utils_1.AST_NODE_TYPES.Identifier) {
+ return;
+ }
+ if (typeName.name !== 'Record') {
+ return;
+ }
+ const params = node.typeArguments?.params;
+ if (params?.length !== 2) {
+ return;
+ }
+ context.report({
+ node,
+ messageId: 'preferIndexSignature',
+ fix(fixer) {
+ const key = sourceCode.getText(params[0]);
+ const type = sourceCode.getText(params[1]);
+ return fixer.replaceText(node, `{ [key: ${key}]: ${type} }`);
+ },
+ });
+ },
+ }),
+ ...(mode === 'record' && {
+ TSTypeLiteral(node) {
+ const parent = findParentDeclaration(node);
+ checkMembers(node.members, node, parent?.id, '', '');
+ },
+ TSInterfaceDeclaration(node) {
+ let genericTypes = '';
+ if (node.typeParameters?.params?.length) {
+ genericTypes = `<${node.typeParameters.params
+ .map(p => sourceCode.getText(p))
+ .join(', ')}>`;
+ }
+ checkMembers(node.body.body, node, node.id, `type ${node.id.name}${genericTypes} = `, ';', !node.extends?.length);
+ },
+ }),
+ };
},
});
diff --git a/dist/rules/consistent-type-assertions.js b/dist/rules/consistent-type-assertions.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-type-assertions.js
+++ b/dist/rules/consistent-type-assertions.js
@@ -34,5 +34,5 @@
docs: {
description: 'Enforce consistent usage of type assertions',
- recommended: 'strict',
+ recommended: 'stylistic',
},
messages: {
@@ -51,4 +51,5 @@
properties: {
assertionStyle: {
+ type: 'string',
enum: ['never'],
},
@@ -61,7 +62,9 @@
properties: {
assertionStyle: {
+ type: 'string',
enum: ['as', 'angle-bracket'],
},
objectLiteralTypeAssertions: {
+ type: 'string',
enum: ['allow', 'allow-as-parameter', 'never'],
},
@@ -137,5 +140,4 @@
}
function checkExpression(node) {
- var _a;
if (options.assertionStyle === 'never' ||
options.objectLiteralTypeAssertions === 'allow' ||
@@ -144,5 +146,4 @@
}
if (options.objectLiteralTypeAssertions === 'allow-as-parameter' &&
- node.parent &&
(node.parent.type === utils_1.AST_NODE_TYPES.NewExpression ||
node.parent.type === utils_1.AST_NODE_TYPES.CallExpression ||
@@ -155,5 +156,5 @@
node.expression.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
const suggest = [];
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.VariableDeclarator &&
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.VariableDeclarator &&
!node.parent.id.typeAnnotation) {
const { parent } = node;
diff --git a/dist/rules/consistent-type-definitions.js b/dist/rules/consistent-type-definitions.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-type-definitions.js
+++ b/dist/rules/consistent-type-definitions.js
@@ -32,5 +32,5 @@
docs: {
description: 'Enforce type definitions to consistently use either `interface` or `type`',
- recommended: 'strict',
+ recommended: 'stylistic',
},
messages: {
@@ -40,4 +40,5 @@
schema: [
{
+ type: 'string',
enum: ['interface', 'type'],
},
@@ -59,63 +60,64 @@
node.global);
}
- return Object.assign(Object.assign({}, (option === 'interface' && {
- "TSTypeAliasDeclaration[typeAnnotation.type='TSTypeLiteral']"(node) {
- context.report({
- node: node.id,
- messageId: 'interfaceOverType',
- fix(fixer) {
- var _a;
- const typeNode = (_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.id;
- const fixes = [];
- const firstToken = sourceCode.getTokenBefore(node.id);
- if (firstToken) {
- fixes.push(fixer.replaceText(firstToken, 'interface'));
- fixes.push(fixer.replaceTextRange([typeNode.range[1], node.typeAnnotation.range[0]], ' '));
- }
- const afterToken = sourceCode.getTokenAfter(node.typeAnnotation);
- if (afterToken &&
- afterToken.type === utils_1.AST_TOKEN_TYPES.Punctuator &&
- afterToken.value === ';') {
- fixes.push(fixer.remove(afterToken));
- }
- return fixes;
- },
- });
- },
- })), (option === 'type' && {
- TSInterfaceDeclaration(node) {
- const fix = isCurrentlyTraversedNodeWithinModuleDeclaration()
- ? null
- : (fixer) => {
- var _a, _b;
- const typeNode = (_a = node.typeParameters) !== null && _a !== void 0 ? _a : node.id;
- const fixes = [];
- const firstToken = sourceCode.getTokenBefore(node.id);
- if (firstToken) {
- fixes.push(fixer.replaceText(firstToken, 'type'));
- fixes.push(fixer.replaceTextRange([typeNode.range[1], node.body.range[0]], ' = '));
- }
- if (node.extends) {
- node.extends.forEach(heritage => {
- const typeIdentifier = sourceCode.getText(heritage);
- fixes.push(fixer.insertTextAfter(node.body, ` & ${typeIdentifier}`));
- });
- }
- if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
- fixes.push(fixer.removeRange([node.parent.range[0], node.range[0]]), fixer.insertTextAfter(node.body, `\nexport default ${node.id.name}`));
- }
- return fixes;
- };
- context.report({
- node: node.id,
- messageId: 'typeOverInterface',
- /**
- * remove automatically fix when the interface is within a declare global
- * @see {@link https://github.com/typescript-eslint/typescript-eslint/issues/2707}
- */
- fix,
- });
- },
- }));
+ return {
+ ...(option === 'interface' && {
+ "TSTypeAliasDeclaration[typeAnnotation.type='TSTypeLiteral']"(node) {
+ context.report({
+ node: node.id,
+ messageId: 'interfaceOverType',
+ fix(fixer) {
+ const typeNode = node.typeParameters ?? node.id;
+ const fixes = [];
+ const firstToken = sourceCode.getTokenBefore(node.id);
+ if (firstToken) {
+ fixes.push(fixer.replaceText(firstToken, 'interface'));
+ fixes.push(fixer.replaceTextRange([typeNode.range[1], node.typeAnnotation.range[0]], ' '));
+ }
+ const afterToken = sourceCode.getTokenAfter(node.typeAnnotation);
+ if (afterToken &&
+ afterToken.type === utils_1.AST_TOKEN_TYPES.Punctuator &&
+ afterToken.value === ';') {
+ fixes.push(fixer.remove(afterToken));
+ }
+ return fixes;
+ },
+ });
+ },
+ }),
+ ...(option === 'type' && {
+ TSInterfaceDeclaration(node) {
+ const fix = isCurrentlyTraversedNodeWithinModuleDeclaration()
+ ? null
+ : (fixer) => {
+ const typeNode = node.typeParameters ?? node.id;
+ const fixes = [];
+ const firstToken = sourceCode.getTokenBefore(node.id);
+ if (firstToken) {
+ fixes.push(fixer.replaceText(firstToken, 'type'));
+ fixes.push(fixer.replaceTextRange([typeNode.range[1], node.body.range[0]], ' = '));
+ }
+ if (node.extends) {
+ node.extends.forEach(heritage => {
+ const typeIdentifier = sourceCode.getText(heritage);
+ fixes.push(fixer.insertTextAfter(node.body, ` & ${typeIdentifier}`));
+ });
+ }
+ if (node.parent?.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
+ fixes.push(fixer.removeRange([node.parent.range[0], node.range[0]]), fixer.insertTextAfter(node.body, `\nexport default ${node.id.name}`));
+ }
+ return fixes;
+ };
+ context.report({
+ node: node.id,
+ messageId: 'typeOverInterface',
+ /**
+ * remove automatically fix when the interface is within a declare global
+ * @see {@link https://github.com/typescript-eslint/typescript-eslint/issues/2707}
+ */
+ fix,
+ });
+ },
+ }),
+ };
},
});
diff --git a/dist/rules/consistent-type-exports.js b/dist/rules/consistent-type-exports.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-type-exports.js
+++ b/dist/rules/consistent-type-exports.js
@@ -33,5 +33,4 @@
docs: {
description: 'Enforce consistent usage of type exports',
- recommended: false,
requiresTypeChecking: true,
},
@@ -62,16 +61,32 @@
const sourceCode = context.getSourceCode();
const sourceExportsMap = {};
- const parserServices = util.getParserServices(context);
+ const services = util.getParserServices(context);
+ /**
+ * Helper for identifying if an export specifier resolves to a
+ * JavaScript value or a TypeScript type.
+ *
+ * @returns True/false if is a type or not, or undefined if the specifier
+ * can't be resolved.
+ */
+ function isSpecifierTypeBased(specifier) {
+ const checker = services.program.getTypeChecker();
+ const symbol = services.getSymbolAtLocation(specifier.exported);
+ const aliasedSymbol = checker.getAliasedSymbol(symbol);
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
+ if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') {
+ return undefined;
+ }
+ return !(aliasedSymbol.flags & typescript_1.SymbolFlags.Value);
+ }
return {
ExportNamedDeclaration(node) {
- var _a;
// Coerce the source into a string for use as a lookup entry.
- const source = (_a = getSourceFromExport(node)) !== null && _a !== void 0 ? _a : 'undefined';
- const sourceExports = (sourceExportsMap[source] || (sourceExportsMap[source] = {
+ const source = getSourceFromExport(node) ?? 'undefined';
+ const sourceExports = (sourceExportsMap[source] ||= {
source,
reportValueExports: [],
typeOnlyNamedExport: null,
valueOnlyNamedExport: null,
- }));
+ });
// Cache the first encountered exports for the package. We will need to come
// back to these later when fixing the problems.
@@ -98,5 +113,5 @@
continue;
}
- const isTypeBased = isSpecifierTypeBased(parserServices, specifier);
+ const isTypeBased = isSpecifierTypeBased(specifier);
if (isTypeBased === true) {
typeBasedSpecifiers.push(specifier);
@@ -177,21 +192,4 @@
});
/**
- * Helper for identifying if an export specifier resolves to a
- * JavaScript value or a TypeScript type.
- *
- * @returns True/false if is a type or not, or undefined if the specifier
- * can't be resolved.
- */
-function isSpecifierTypeBased(parserServices, specifier) {
- const checker = parserServices.program.getTypeChecker();
- const node = parserServices.esTreeNodeToTSNodeMap.get(specifier.exported);
- const symbol = checker.getSymbolAtLocation(node);
- const aliasedSymbol = checker.getAliasedSymbol(symbol);
- if (!aliasedSymbol || aliasedSymbol.escapedName === 'unknown') {
- return undefined;
- }
- return !(aliasedSymbol.flags & typescript_1.SymbolFlags.Value);
-}
-/**
* Inserts "type" into an export.
*
@@ -248,6 +246,5 @@
*/
function getSourceFromExport(node) {
- var _a;
- if (((_a = node.source) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Literal &&
+ if (node.source?.type === utils_1.AST_NODE_TYPES.Literal &&
typeof node.source.value === 'string') {
return node.source.value;
diff --git a/dist/rules/consistent-type-imports.js b/dist/rules/consistent-type-imports.js
index v5.60.1..v6.1.0 100644
--- a/dist/rules/consistent-type-imports.js
+++ b/dist/rules/consistent-type-imports.js
@@ -32,5 +32,4 @@
docs: {
description: 'Enforce consistent usage of type imports',
- recommended: false,
},
messages: {
@@ -48,4 +47,5 @@
properties: {
prefer: {
+ type: 'string',
enum: ['type-imports', 'no-type-imports'],
},
@@ -54,4 +54,5 @@
},
fixStyle: {
+ type: 'string',
enum: ['separate-type-imports', 'inline-type-imports'],
},
@@ -70,240 +71,244 @@
],
create(context, [option]) {
- var _a, _b;
- const prefer = (_a = option.prefer) !== null && _a !== void 0 ? _a : 'type-imports';
+ const prefer = option.prefer ?? 'type-imports';
const disallowTypeAnnotations = option.disallowTypeAnnotations !== false;
- const fixStyle = (_b = option.fixStyle) !== null && _b !== void 0 ? _b : 'separate-type-imports';
+ const fixStyle = option.fixStyle ?? 'separate-type-imports';
const sourceCode = context.getSourceCode();
const sourceImportsMap = {};
- return Object.assign(Object.assign({}, (prefer === 'type-imports'
- ? {
- // prefer type imports
- ImportDeclaration(node) {
- var _a;
- const source = node.source.value;
- // sourceImports is the object containing all the specifics for a particular import source, type or value
- const sourceImports = (_a = sourceImportsMap[source]) !== null && _a !== void 0 ? _a : (sourceImportsMap[source] = {
- source,
- reportValueImports: [],
- typeOnlyNamedImport: null,
- valueOnlyNamedImport: null,
- valueImport: null, // if only value imports
- });
- if (node.importKind === 'type') {
- if (!sourceImports.typeOnlyNamedImport &&
- node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
- // definitely import type { TypeX }
- sourceImports.typeOnlyNamedImport = node;
+ return {
+ ...(prefer === 'type-imports'
+ ? {
+ // prefer type imports
+ ImportDeclaration(node) {
+ const source = node.source.value;
+ // sourceImports is the object containing all the specifics for a particular import source, type or value
+ const sourceImports = sourceImportsMap[source] ??
+ (sourceImportsMap[source] = {
+ source,
+ reportValueImports: [],
+ typeOnlyNamedImport: null,
+ valueOnlyNamedImport: null,
+ valueImport: null, // if only value imports
+ });
+ if (node.importKind === 'type') {
+ if (!sourceImports.typeOnlyNamedImport &&
+ node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
+ // definitely import type { TypeX }
+ sourceImports.typeOnlyNamedImport = node;
+ }
}
- }
- else {
- if (!sourceImports.valueOnlyNamedImport &&
- node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
- sourceImports.valueOnlyNamedImport = node;
- sourceImports.valueImport = node;
+ else {
+ if (!sourceImports.valueOnlyNamedImport &&
+ node.specifiers.every(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier)) {
+ sourceImports.valueOnlyNamedImport = node;
+ sourceImports.valueImport = node;
+ }
+ else if (!sourceImports.valueImport &&
+ node.specifiers.some(specifier => specifier.type === utils_1.AST_NODE_TYPES.ImportDefaultSpecifier)) {
+ sourceImports.valueImport = node;
+ }
}
- else if (!sourceImports.valueImport &&
- (too long so truncated)
Command detailsnpm diff --diff=@typescript-eslint/eslint-plugin@5.60.1 --diff=@typescript-eslint/eslint-plugin@6.1.0 --diff-unified=2 See also the Reported by ybiquitous/npm-diff-action@v1.4.1 (Node.js 18.16.1 and npm 9.8.1) |
dependabot
bot
force-pushed
the
dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.1.0
branch
2 times, most recently
from
July 20, 2023 03:18
0e8c6c3
to
55a23ce
Compare
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.60.1 to 6.1.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v6.1.0/packages/eslint-plugin) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
dependabot
bot
force-pushed
the
dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.1.0
branch
from
July 20, 2023 03:24
55a23ce
to
312ff46
Compare
ybiquitous
changed the title
chore(deps-dev): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
typescript(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
Jul 20, 2023
ybiquitous
changed the title
typescript(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
feat(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
Jul 20, 2023
ybiquitous
changed the title
feat(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
feat!(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
Jul 20, 2023
ybiquitous
changed the title
feat!(deps): bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
feat(deps)!: bump @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0
Jul 20, 2023
ybiquitous
deleted the
dependabot/npm_and_yarn/typescript-eslint/eslint-plugin-6.1.0
branch
July 20, 2023 04:44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
dependencies
Pull requests that update a dependency file
javascript
Pull requests that update Javascript code
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bumps @typescript-eslint/eslint-plugin from 5.60.1 to 6.1.0.
Release notes
Sourced from
@typescript-eslint/eslint-plugin
's releases.... (truncated)
Changelog
Sourced from
@typescript-eslint/eslint-plugin
's changelog.... (truncated)
Commits
d98f1e8
chore: publish v6.1.01404796
fix(eslint-plugin): [no-unnecessary-type-constraint] correctly fix in cts/mts...587ac30
fix(eslint-plugin): [no-unused-vars] check if any variable definition is expo...2a4421c
fix(eslint-plugin): [no-floating-promises] finally should be transparent to u...6d3d162
feat(typescript-estree): add EXPERIMENTAL_useProjectService option to use Typ...606a52c
fix(eslint-plugin): [no-floating-promises] false negative calling .then with ...d368164
fix(eslint-plugin): [comma-dangle] fixed crash from undefined predicate.ignor...e08a722
docs: fix typo in explicit-member-accessibility (#7224)a3da11d
fix(eslint-plugin): include the rules types in the package (#7215)2e30379
chore: bump dependency versions (#7191)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)