diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7c56ffa67e..ae2d6ac88510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + + +### Bug Fixes + +* **eslint-plugin:** [no-namespace] allow namespaces in nested declarations with `allowDeclarations` ([#2238](https://github.com/typescript-eslint/typescript-eslint/issues/2238)) ([c1df669](https://github.com/typescript-eslint/typescript-eslint/commit/c1df6694f7866d3ef7ede0b1c6c9dd6f3955e682)) +* **eslint-plugin:** [space-before-function-paren] handle abstract functions ([#2199](https://github.com/typescript-eslint/typescript-eslint/issues/2199)) ([88a3edf](https://github.com/typescript-eslint/typescript-eslint/commit/88a3edfce8349f871b7b660d2b76508b67c94eda)) + + +### Features + +* **eslint-plugin:** add rule `prefer-literal-enum-member` ([#1898](https://github.com/typescript-eslint/typescript-eslint/issues/1898)) ([fe2b2ec](https://github.com/typescript-eslint/typescript-eslint/commit/fe2b2ec39ef04ac8b73eef9d29d12fd1b24fa183)) + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/lerna.json b/lerna.json index 9a433aaf75dc..3cdd9d61405e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "3.5.0", + "version": "3.6.0", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/packages/eslint-plugin-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md index db3bae7fe132..ce050cf30378 100644 --- a/packages/eslint-plugin-internal/CHANGELOG.md +++ b/packages/eslint-plugin-internal/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/eslint-plugin-internal/package.json b/packages/eslint-plugin-internal/package.json index 2c4b6aa1e100..0907aafd1b80 100644 --- a/packages/eslint-plugin-internal/package.json +++ b/packages/eslint-plugin-internal/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-internal", - "version": "3.5.0", + "version": "3.6.0", "private": true, "main": "dist/index.js", "scripts": { @@ -13,7 +13,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "3.5.0", + "@typescript-eslint/experimental-utils": "3.6.0", "prettier": "*" } } diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index a29298520349..81ed76ab7b4c 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 43146ce8d6e7..1b11aad35965 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "3.5.0", + "version": "3.6.0", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -32,7 +32,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "3.5.0", + "@typescript-eslint/experimental-utils": "3.6.0", "lodash": "^4.17.15" }, "peerDependencies": { @@ -42,6 +42,6 @@ }, "devDependencies": { "@types/lodash": "^4.14.149", - "@typescript-eslint/parser": "3.5.0" + "@typescript-eslint/parser": "3.6.0" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index bf8c2c48205b..8051b80392b5 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + + +### Bug Fixes + +* **eslint-plugin:** [no-namespace] allow namespaces in nested declarations with `allowDeclarations` ([#2238](https://github.com/typescript-eslint/typescript-eslint/issues/2238)) ([c1df669](https://github.com/typescript-eslint/typescript-eslint/commit/c1df6694f7866d3ef7ede0b1c6c9dd6f3955e682)) +* **eslint-plugin:** [space-before-function-paren] handle abstract functions ([#2199](https://github.com/typescript-eslint/typescript-eslint/issues/2199)) ([88a3edf](https://github.com/typescript-eslint/typescript-eslint/commit/88a3edfce8349f871b7b660d2b76508b67c94eda)) + + +### Features + +* **eslint-plugin:** add rule `prefer-literal-enum-member` ([#1898](https://github.com/typescript-eslint/typescript-eslint/issues/1898)) ([fe2b2ec](https://github.com/typescript-eslint/typescript-eslint/commit/fe2b2ec39ef04ac8b73eef9d29d12fd1b24fa183)) + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/eslint-plugin/README.md b/packages/eslint-plugin/README.md index 5f9822ed12f4..b33606921784 100644 --- a/packages/eslint-plugin/README.md +++ b/packages/eslint-plugin/README.md @@ -150,6 +150,7 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int | [`@typescript-eslint/prefer-for-of`](./docs/rules/prefer-for-of.md) | Prefer a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated | | | | | [`@typescript-eslint/prefer-function-type`](./docs/rules/prefer-function-type.md) | Use function types instead of interfaces with call signatures | | :wrench: | | | [`@typescript-eslint/prefer-includes`](./docs/rules/prefer-includes.md) | Enforce `includes` method over `indexOf` method | | :wrench: | :thought_balloon: | +| [`@typescript-eslint/prefer-literal-enum-member`](./docs/rules/prefer-literal-enum-member.md) | Require that all enum members be literal values to prevent unintended enum member name shadow issues | | | | | [`@typescript-eslint/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) | Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules | :heavy_check_mark: | :wrench: | | | [`@typescript-eslint/prefer-nullish-coalescing`](./docs/rules/prefer-nullish-coalescing.md) | Enforce the usage of the nullish coalescing operator instead of logical chaining | | | :thought_balloon: | | [`@typescript-eslint/prefer-optional-chain`](./docs/rules/prefer-optional-chain.md) | Prefer using concise optional chain expressions instead of chained logical ands | | | | diff --git a/packages/eslint-plugin/docs/rules/no-namespace.md b/packages/eslint-plugin/docs/rules/no-namespace.md index d82ad724b7b3..b155c2aeb307 100644 --- a/packages/eslint-plugin/docs/rules/no-namespace.md +++ b/packages/eslint-plugin/docs/rules/no-namespace.md @@ -51,6 +51,14 @@ Examples of **correct** code for the `{ "allowDeclarations": true }` option: declare module 'foo' {} declare module foo {} declare namespace foo {} + +declare global { + namespace foo {} +} + +declare module foo { + namespace foo {} +} ``` Examples of **incorrect** code for the `{ "allowDeclarations": false }` option: diff --git a/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md new file mode 100644 index 000000000000..e2350f357113 --- /dev/null +++ b/packages/eslint-plugin/docs/rules/prefer-literal-enum-member.md @@ -0,0 +1,51 @@ +# Require that all enum members be literal values to prevent unintended enum member name shadow issues (`prefer-literal-enum-member`) + +TypeScript allows the value of an enum member to be many different kinds of valid JavaScript expressions. However, because enums create their own scope whereby each enum member becomes a variable in that scope, unexpected values could be used at runtime. Example: + +```ts +const imOutside = 2; +const b = 2; +enum Foo { + outer = imOutside, + a = 1, + b = a, + c = b, + // does c == Foo.b == Foo.c == 1? + // or does c == b == 2? +} +``` + +The answer is that `Foo.c` will be `1` at runtime. The [playground](https://www.typescriptlang.org/play/#src=const%20imOutside%20%3D%202%3B%0D%0Aconst%20b%20%3D%202%3B%0D%0Aenum%20Foo%20%7B%0D%0A%20%20%20%20outer%20%3D%20imOutside%2C%0D%0A%20%20%20%20a%20%3D%201%2C%0D%0A%20%20%20%20b%20%3D%20a%2C%0D%0A%20%20%20%20c%20%3D%20b%2C%0D%0A%20%20%20%20%2F%2F%20does%20c%20%3D%3D%20Foo.b%20%3D%3D%20Foo.c%20%3D%3D%201%3F%0D%0A%20%20%20%20%2F%2F%20or%20does%20c%20%3D%3D%20b%20%3D%3D%202%3F%0D%0A%7D) illustrates this quite nicely. + +## Rule Details + +This rule is meant to prevent unexpected results in code by requiring the use of literal values as enum members to prevent unexpected runtime behavior. Template literals, arrays, objects, constructors, and all other expression types can end up using a variable from its scope or the parent scope, which can result in the same unexpected behavior at runtime. + +Examples of **incorrect** code for this rule: + +```ts +const str = 'Test'; +enum Invalid { + A = str, // Variable assignment + B = {}, // Object assignment + C = `A template literal string`, // Template literal + D = new Set(1, 2, 3), // Constructor in assignment + E = 2 + 2, // Expression assignment +} +``` + +Examples of **correct** code for this rule: + +```ts +enum Valid { + A, + B = 'TestStr', // A regular string + C = 4, // A number + D = null, + E = /some_regex/, +} +``` + +## When Not To Use It + +If you want use anything other than simple literals as an enum value. diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 2924c650d6d1..1547b3d95157 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "3.5.0", + "version": "3.6.0", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -42,7 +42,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "3.5.0", + "@typescript-eslint/experimental-utils": "3.6.0", "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", diff --git a/packages/eslint-plugin/src/configs/all.ts b/packages/eslint-plugin/src/configs/all.ts index 68923e26e8a2..e78feb7d44ac 100644 --- a/packages/eslint-plugin/src/configs/all.ts +++ b/packages/eslint-plugin/src/configs/all.ts @@ -100,6 +100,7 @@ export = { '@typescript-eslint/prefer-for-of': 'error', '@typescript-eslint/prefer-function-type': 'error', '@typescript-eslint/prefer-includes': 'error', + '@typescript-eslint/prefer-literal-enum-member': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', '@typescript-eslint/prefer-nullish-coalescing': 'error', '@typescript-eslint/prefer-optional-chain': 'error', diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index 37ad1da48062..73083bedfe41 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -17,7 +17,9 @@ import explicitMemberAccessibility from './explicit-member-accessibility'; import explicitModuleBoundaryTypes from './explicit-module-boundary-types'; import funcCallSpacing from './func-call-spacing'; import indent from './indent'; +import initDeclarations from './init-declarations'; import keywordSpacing from './keyword-spacing'; +import linesBetweenClassMembers from './lines-between-class-members'; import memberDelimiterStyle from './member-delimiter-style'; import memberOrdering from './member-ordering'; import methodSignatureStyle from './method-signature-style'; @@ -35,10 +37,12 @@ import noExtraParens from './no-extra-parens'; import noExtraSemi from './no-extra-semi'; import noFloatingPromises from './no-floating-promises'; import noForInArray from './no-for-in-array'; +import preferLiteralEnumMember from './prefer-literal-enum-member'; import noImpliedEval from './no-implied-eval'; import noInferrableTypes from './no-inferrable-types'; import noInvalidThis from './no-invalid-this'; import noInvalidVoidType from './no-invalid-void-type'; +import noLossOfPrecision from './no-loss-of-precision'; import noMagicNumbers from './no-magic-numbers'; import noMisusedNew from './no-misused-new'; import noMisusedPromises from './no-misused-promises'; @@ -85,7 +89,6 @@ import requireAwait from './require-await'; import restrictPlusOperands from './restrict-plus-operands'; import restrictTemplateExpressions from './restrict-template-expressions'; import returnAwait from './return-await'; -import initDeclarations from './init-declarations'; import semi from './semi'; import spaceBeforeFunctionParen from './space-before-function-paren'; import strictBooleanExpressions from './strict-boolean-expressions'; @@ -95,8 +98,6 @@ import typeAnnotationSpacing from './type-annotation-spacing'; import typedef from './typedef'; import unboundMethod from './unbound-method'; import unifiedSignatures from './unified-signatures'; -import linesBetweenClassMembers from './lines-between-class-members'; -import noLossOfPrecision from './no-loss-of-precision'; export default { 'adjacent-overload-signatures': adjacentOverloadSignatures, @@ -171,6 +172,7 @@ export default { 'prefer-for-of': preferForOf, 'prefer-function-type': preferFunctionType, 'prefer-includes': preferIncludes, + 'prefer-literal-enum-member': preferLiteralEnumMember, 'prefer-namespace-keyword': preferNamespaceKeyword, 'prefer-nullish-coalescing': preferNullishCoalescing, 'prefer-optional-chain': preferOptionalChain, diff --git a/packages/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index 3698b4f941bd..f8cc05b10471 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -50,6 +50,14 @@ export default util.createRule({ create(context, [{ allowDeclarations, allowDefinitionFiles }]) { const filename = context.getFilename(); + function isDeclaration(node: TSESTree.TSModuleDeclaration): boolean { + return ( + node.declare === true || + (node.parent!.parent?.type === AST_NODE_TYPES.TSModuleDeclaration && + isDeclaration(node.parent!.parent)) + ); + } + return { "TSModuleDeclaration[global!=true][id.type='Identifier']"( node: TSESTree.TSModuleDeclaration, @@ -58,7 +66,7 @@ export default util.createRule({ (node.parent && node.parent.type === AST_NODE_TYPES.TSModuleDeclaration) || (allowDefinitionFiles && util.isDefinitionFile(filename)) || - (allowDeclarations && node.declare === true) + (allowDeclarations && isDeclaration(node)) ) { return; } diff --git a/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts b/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts new file mode 100644 index 000000000000..8f95fd5946b5 --- /dev/null +++ b/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts @@ -0,0 +1,37 @@ +import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils'; +import { createRule } from '../util'; + +export default createRule<[], 'notLiteral'>({ + name: 'prefer-literal-enum-member', + meta: { + type: 'suggestion', + docs: { + description: + 'Require that all enum members be literal values to prevent unintended enum member name shadow issues', + category: 'Best Practices', + recommended: false, + requiresTypeChecking: false, + }, + messages: { + notLiteral: `Explicit enum value must only be a literal value (string, number, boolean, etc).`, + }, + schema: [], + }, + defaultOptions: [], + create(context) { + return { + TSEnumMember(node): void { + // If there is no initializer, then this node is just the name of the member, so ignore. + if ( + node.initializer != null && + node.initializer.type !== AST_NODE_TYPES.Literal + ) { + context.report({ + node: node.id, + messageId: 'notLiteral', + }); + } + }, + }; + }, +}); diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index 41a817938dac..f06327e2dd59 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -75,9 +75,10 @@ export default util.createRule({ node: | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression, + | TSESTree.FunctionExpression + | TSESTree.TSAbstractMethodDefinition, ): boolean { - if (node.id) { + if ('id' in node && node.id != null) { return true; } @@ -85,6 +86,7 @@ export default util.createRule({ return ( parent.type === AST_NODE_TYPES.MethodDefinition || + parent.type === AST_NODE_TYPES.TSAbstractMethodDefinition || (parent.type === AST_NODE_TYPES.Property && (parent.kind === 'get' || parent.kind === 'set' || parent.method)) ); @@ -99,7 +101,8 @@ export default util.createRule({ node: | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression, + | TSESTree.FunctionExpression + | TSESTree.TSAbstractMethodDefinition, ): FuncOption { if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) { // Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar @@ -113,7 +116,7 @@ export default util.createRule({ return overrideConfig.named ?? baseConfig; // `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}` - } else if (!node.generator) { + } else if (!('generator' in node) || node.generator === false) { return overrideConfig.anonymous ?? baseConfig; } @@ -129,7 +132,8 @@ export default util.createRule({ node: | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression, + | TSESTree.FunctionExpression + | TSESTree.TSAbstractMethodDefinition, ): void { const functionConfig = getConfigForFunction(node); @@ -161,7 +165,7 @@ export default util.createRule({ } else if ( !hasSpacing && functionConfig === 'always' && - (!node.typeParameters || node.id) + (!node.typeParameters || ('id' in node && node != null)) ) { context.report({ node, @@ -176,6 +180,7 @@ export default util.createRule({ ArrowFunctionExpression: checkFunction, FunctionDeclaration: checkFunction, FunctionExpression: checkFunction, + TSAbstractMethodDefinition: checkFunction, }; }, }); diff --git a/packages/eslint-plugin/tests/rules/no-namespace.test.ts b/packages/eslint-plugin/tests/rules/no-namespace.test.ts index e175f5895dfc..3bb9079b3fc3 100644 --- a/packages/eslint-plugin/tests/rules/no-namespace.test.ts +++ b/packages/eslint-plugin/tests/rules/no-namespace.test.ts @@ -17,6 +17,42 @@ ruleTester.run('no-namespace', rule, { code: 'declare namespace foo {}', options: [{ allowDeclarations: true }], }, + { + code: ` +declare global { + namespace foo {} +} + `, + options: [{ allowDeclarations: true }], + }, + { + code: ` +declare module foo { + namespace bar {} +} + `, + options: [{ allowDeclarations: true }], + }, + { + code: ` +declare global { + namespace foo { + namespace bar {} + } +} + `, + options: [{ allowDeclarations: true }], + }, + { + code: ` +declare namespace foo { + namespace bar { + namespace baz {} + } +} + `, + options: [{ allowDeclarations: true }], + }, { filename: 'test.d.ts', code: 'namespace foo {}', @@ -71,6 +107,28 @@ ruleTester.run('no-namespace', rule, { }, ], }, + { + code: 'module foo {}', + options: [{ allowDeclarations: true }], + errors: [ + { + messageId: 'moduleSyntaxIsPreferred', + line: 1, + column: 1, + }, + ], + }, + { + code: 'namespace foo {}', + options: [{ allowDeclarations: true }], + errors: [ + { + messageId: 'moduleSyntaxIsPreferred', + line: 1, + column: 1, + }, + ], + }, { code: 'declare module foo {}', errors: [ diff --git a/packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts b/packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts new file mode 100644 index 000000000000..4e309edc3572 --- /dev/null +++ b/packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts @@ -0,0 +1,206 @@ +import rule from '../../src/rules/prefer-literal-enum-member'; +import { RuleTester, noFormat } from '../RuleTester'; + +const ruleTester = new RuleTester({ + parser: '@typescript-eslint/parser', +}); + +ruleTester.run('prefer-literal-enum-member', rule, { + valid: [ + ` +enum ValidRegex { + A = /test/, +} + `, + ` +enum ValidString { + A = 'test', +} + `, + ` +enum ValidNumber { + A = 42, +} + `, + ` +enum ValidNull { + A = null, +} + `, + ` +enum ValidPlain { + A, +} + `, + ` +enum ValidQuotedKey { + 'a', +} + `, + ` +enum ValidQuotedKeyWithAssignment { + 'a' = 1, +} + `, + noFormat` +enum ValidKeyWithComputedSyntaxButNoComputedKey { + ['a'], +} + `, + ], + invalid: [ + { + code: ` +enum InvalidObject { + A = {}, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 3, + column: 3, + }, + ], + }, + { + code: ` +enum InvalidArray { + A = [], +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 3, + column: 3, + }, + ], + }, + { + code: ` +enum InvalidTemplateLiteral { + A = \`a\`, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 3, + column: 3, + }, + ], + }, + { + code: ` +enum InvalidConstructor { + A = new Set(), +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 3, + column: 3, + }, + ], + }, + { + code: ` +enum InvalidExpression { + A = 2 + 2, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 3, + column: 3, + }, + ], + }, + { + code: ` +const variable = 'Test'; +enum InvalidVariable { + A = 'TestStr', + B = 2, + C, + V = variable, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 7, + column: 3, + }, + ], + }, + { + code: ` +enum InvalidEnumMember { + A = 'TestStr', + B = A, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 4, + column: 3, + }, + ], + }, + { + code: ` +const Valid = { A: 2 }; +enum InvalidObjectMember { + A = 'TestStr', + B = Valid.A, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 5, + column: 3, + }, + ], + }, + { + code: ` +enum Valid { + A, +} +enum InvalidEnumMember { + A = 'TestStr', + B = Valid.A, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 7, + column: 3, + }, + ], + }, + { + code: ` +const obj = { a: 1 }; +enum InvalidSpread { + A = 'TestStr', + B = { ...a }, +} + `, + errors: [ + { + messageId: 'notLiteral', + line: 5, + column: 3, + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts b/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts index 944ea672f1fc..5de3b0e6378d 100644 --- a/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts +++ b/packages/eslint-plugin/tests/rules/space-before-function-paren.test.ts @@ -148,6 +148,11 @@ ruleTester.run('space-before-function-paren', rule, { options: ['never'], parserOptions: { ecmaVersion: 8 }, }, + 'abstract class Foo { constructor () {} abstract method () }', + { + code: 'abstract class Foo { constructor() {} abstract method() }', + options: ['never'], + }, ], invalid: [ diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index 1f929682a0e8..2c9cc15b7aff 100644 --- a/packages/experimental-utils/CHANGELOG.md +++ b/packages/experimental-utils/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/experimental-utils + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index 767f62cc5ce6..74a9004ce2fc 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "3.5.0", + "version": "3.6.0", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -40,8 +40,8 @@ }, "dependencies": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/types": "3.5.0", - "@typescript-eslint/typescript-estree": "3.5.0", + "@typescript-eslint/types": "3.6.0", + "@typescript-eslint/typescript-estree": "3.6.0", "eslint-scope": "^5.0.0", "eslint-utils": "^2.0.0" }, diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 5546c0b73175..6dd2906e4c34 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/parser + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/parser/package.json b/packages/parser/package.json index 6e148f6fd6a0..f2d1576fed76 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "3.5.0", + "version": "3.6.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -44,14 +44,14 @@ }, "dependencies": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "3.5.0", - "@typescript-eslint/types": "3.5.0", - "@typescript-eslint/typescript-estree": "3.5.0", + "@typescript-eslint/experimental-utils": "3.6.0", + "@typescript-eslint/types": "3.6.0", + "@typescript-eslint/typescript-estree": "3.6.0", "eslint-visitor-keys": "^1.1.0" }, "devDependencies": { "@types/glob": "^7.1.1", - "@typescript-eslint/shared-fixtures": "3.5.0", + "@typescript-eslint/shared-fixtures": "3.6.0", "glob": "*" }, "peerDependenciesMeta": { diff --git a/packages/scope-manager/CHANGELOG.md b/packages/scope-manager/CHANGELOG.md index d10d51b02728..1191cc8da765 100644 --- a/packages/scope-manager/CHANGELOG.md +++ b/packages/scope-manager/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/scope-manager + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index d744f06abc64..c9d9b849d9b4 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/scope-manager", - "version": "3.5.0", + "version": "3.6.0", "description": "TypeScript scope analyser for ESLint", "keywords": [ "eslint", @@ -38,13 +38,13 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "3.5.0", - "@typescript-eslint/visitor-keys": "3.5.0" + "@typescript-eslint/types": "3.6.0", + "@typescript-eslint/visitor-keys": "3.6.0" }, "devDependencies": { "@types/jest-specific-snapshot": "^0.5.4", "@types/mkdirp": "^1.0.0", - "@typescript-eslint/typescript-estree": "3.5.0", + "@typescript-eslint/typescript-estree": "3.6.0", "glob": "^7.1.6", "jest-specific-snapshot": "^3.0.0", "make-dir": "^3.1.0", diff --git a/packages/shared-fixtures/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 7ebb3d0392d3..5a5551971d3b 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/shared-fixtures + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) **Note:** Version bump only for package @typescript-eslint/shared-fixtures diff --git a/packages/shared-fixtures/package.json b/packages/shared-fixtures/package.json index b43e9711d054..835422a5c96e 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "3.5.0", + "version": "3.6.0", "private": true, "scripts": { "build": "tsc -b tsconfig.build.json", diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 426aa07c3e92..84e9cb6803c5 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/types + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/types/package.json b/packages/types/package.json index 68da67c2f6e5..ef8209c1adc6 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/types", - "version": "3.5.0", + "version": "3.6.0", "description": "Types for the TypeScript-ESTree AST spec", "keywords": [ "eslint", diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index b9404d15ea6e..49679224bd52 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/typescript-estree + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 59cb4e60e5fc..0a6d8c9bda6c 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "3.5.0", + "version": "3.6.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -40,8 +40,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "3.5.0", - "@typescript-eslint/visitor-keys": "3.5.0", + "@typescript-eslint/types": "3.6.0", + "@typescript-eslint/visitor-keys": "3.6.0", "debug": "^4.1.1", "glob": "^7.1.6", "is-glob": "^4.0.1", @@ -60,7 +60,7 @@ "@types/lodash": "^4.14.149", "@types/semver": "^7.1.0", "@types/tmp": "^0.2.0", - "@typescript-eslint/shared-fixtures": "3.5.0", + "@typescript-eslint/shared-fixtures": "3.6.0", "tmp": "^0.2.1", "typescript": "*" }, diff --git a/packages/visitor-keys/CHANGELOG.md b/packages/visitor-keys/CHANGELOG.md index 4c1a5587d068..d7cb5e4f7408 100644 --- a/packages/visitor-keys/CHANGELOG.md +++ b/packages/visitor-keys/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [3.6.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.5.0...v3.6.0) (2020-07-06) + +**Note:** Version bump only for package @typescript-eslint/visitor-keys + + + + + # [3.5.0](https://github.com/typescript-eslint/typescript-eslint/compare/v3.4.0...v3.5.0) (2020-06-29) diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index b5e54399de27..13ca2d81037a 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/visitor-keys", - "version": "3.5.0", + "version": "3.6.0", "description": "Visitor keys used to help traverse the TypeScript-ESTree AST", "keywords": [ "eslint", @@ -39,7 +39,7 @@ "eslint-visitor-keys": "^1.1.0" }, "devDependencies": { - "@typescript-eslint/types": "3.5.0" + "@typescript-eslint/types": "3.6.0" }, "funding": { "type": "opencollective",