From f28ef1259a36dd171b49db2a45031b9c368f1de1 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 20 May 2023 23:15:11 -0400 Subject: [PATCH 1/3] Converted strict-export-declare-modifiers from TSLint to ESLint, ish --- packages/dtslint/dtslint.json | 1 - .../rules/strict-export-declare-modifiers.ts | 193 ++++++++++++++++++ .../rules/strictExportDeclareModifiersRule.ts | 173 ---------------- .../strict-export-declare-modifiers.test.ts | 158 ++++++++++++++ .../testAmbient.d.ts.lint | 24 --- .../testModule.d.ts.lint | 23 --- .../testModuleAutoExport.d.ts.lint | 27 --- .../testModuleTs.ts.lint | 20 -- .../testValues.d.ts.lint | 2 - .../tslint.json | 6 - 10 files changed, 351 insertions(+), 276 deletions(-) create mode 100644 packages/dtslint/src/rules/strict-export-declare-modifiers.ts delete mode 100644 packages/dtslint/src/rules/strictExportDeclareModifiersRule.ts create mode 100644 packages/dtslint/test/strict-export-declare-modifiers.test.ts delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/testAmbient.d.ts.lint delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/testModule.d.ts.lint delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/testModuleAutoExport.d.ts.lint delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/testModuleTs.ts.lint delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/testValues.d.ts.lint delete mode 100644 packages/dtslint/test/strict-export-declare-modifiers/tslint.json diff --git a/packages/dtslint/dtslint.json b/packages/dtslint/dtslint.json index f0361f5c4b..f1df55bfb7 100644 --- a/packages/dtslint/dtslint.json +++ b/packages/dtslint/dtslint.json @@ -6,7 +6,6 @@ "expect": true, "no-padding": true, "no-relative-import-in-test": true, - "strict-export-declare-modifiers": true, "no-single-declare-module": true, "unified-signatures": true, "void-return": true, diff --git a/packages/dtslint/src/rules/strict-export-declare-modifiers.ts b/packages/dtslint/src/rules/strict-export-declare-modifiers.ts new file mode 100644 index 0000000000..fee7fb66a5 --- /dev/null +++ b/packages/dtslint/src/rules/strict-export-declare-modifiers.ts @@ -0,0 +1,193 @@ +import { ESLintUtils } from "@typescript-eslint/utils"; +import * as ts from "typescript"; +import { createRule } from "../util"; + +const rule = createRule({ + name: "strict-export-declare-modifiers", + defaultOptions: [], + meta: { + type: "problem", + docs: { + description: "Enforces strict rules about where the 'export' and 'declare' modifiers may appear.", + recommended: "error", + }, + messages: { + missingExplicitExport: + "All declarations in this module are exported automatically. " + + "Prefer to explicitly write 'export' for clarity. " + + "If you have a good reason not to export this declaration, " + + "add 'export {}' to the module to shut off automatic exporting.", + redundantDeclare: "'declare' keyword is redundant here.", + redundantExport: + "'export' keyword is redundant here because " + + "all declarations in this module are exported automatically. " + + "If you have a good reason to export some declarations and not others, " + + "add 'export {}' to the module to shut off automatic exporting.", + }, + schema: [], + }, + // TODO: This code is a modified version of the old TSLint rule, + // and still primarily uses TypeScript nodes. It would be better + // to switch it to using TSESTree nodes like other ESLint rules. + create(context) { + const services = ESLintUtils.getParserServices(context, true); + const sourceCode = context.getSourceCode(); + const sourceFile = services.esTreeNodeToTSNodeMap.get(sourceCode.ast); + + const isExternal = + sourceFile.isDeclarationFile && + !sourceFile.statements.some( + (s) => + s.kind === ts.SyntaxKind.ExportAssignment || + (s.kind === ts.SyntaxKind.ExportDeclaration && !!(s as ts.ExportDeclaration).exportClause) + ) && + ts.isExternalModule(sourceFile); + + for (const node of sourceFile.statements) { + if (isExternal) { + checkInExternalModule(node, isAutomaticExport(sourceFile)); + } else { + checkInOther(node, sourceFile.isDeclarationFile); + } + + if (isModuleDeclaration(node) && (sourceFile.isDeclarationFile || isDeclare(node))) { + checkModule(node); + } + } + + function checkInExternalModule(node: ts.Statement, autoExportEnabled: boolean) { + // Ignore certain node kinds (these can't have 'export' or 'default' modifiers) + switch (node.kind) { + case ts.SyntaxKind.ImportDeclaration: + case ts.SyntaxKind.ImportEqualsDeclaration: + case ts.SyntaxKind.ExportDeclaration: + case ts.SyntaxKind.NamespaceExportDeclaration: + return; + } + + // `declare global` and `declare module "foo"` OK. `declare namespace N` not OK, should be `export namespace`. + if (!isDeclareGlobalOrExternalModuleDeclaration(node)) { + if (isDeclare(node)) { + context.report({ + loc: getModifierLoc(node as ts.HasModifiers, ts.SyntaxKind.DeclareKeyword)!, + messageId: "redundantDeclare", + }); + } + if (autoExportEnabled && !isExport(node)) { + context.report({ + messageId: "missingExplicitExport", + node: services.tsNodeToESTreeNodeMap.get((node as ts.DeclarationStatement).name || node), + }); + } + } + } + + function checkInOther(node: ts.Statement, inDeclarationFile: boolean): void { + // Compiler will enforce presence of 'declare' where necessary. But types do not need 'declare'. + if (isDeclare(node)) { + if ( + (isExport(node) && inDeclarationFile) || + ts.isInterfaceDeclaration(node) || + ts.isTypeAliasDeclaration(node) + ) { + context.report({ + loc: getModifierLoc(node as ts.HasModifiers, ts.SyntaxKind.DeclareKeyword), + messageId: "redundantDeclare", + }); + } + } + } + + function getModifierLoc(node: ts.HasModifiers, kind: ts.SyntaxKind) { + const modifier = ts.getModifiers(node)?.find((modifier) => modifier.kind === kind)!; + + return { + end: sourceCode.getLocFromIndex(modifier.end), + start: sourceCode.getLocFromIndex(modifier.getStart(sourceFile)), + }; + } + + function checkModule(moduleDeclaration: ts.ModuleDeclaration): void { + const body = moduleDeclaration.body; + if (!body) { + return; + } + + switch (body.kind) { + case ts.SyntaxKind.ModuleDeclaration: + checkModule(body); + break; + case ts.SyntaxKind.ModuleBlock: + checkBlock(body, isAutomaticExport(moduleDeclaration)); + break; + } + } + + function checkBlock(block: ts.ModuleBlock, autoExportEnabled: boolean): void { + for (const statement of block.statements) { + // Compiler will error for 'declare' here anyway, so just check for 'export'. + if (isExport(statement) && autoExportEnabled && !isDefault(statement)) { + context.report({ + loc: getModifierLoc(statement as ts.HasModifiers, ts.SyntaxKind.ExportKeyword), + messageId: "redundantExport", + }); + } + + if (isModuleDeclaration(statement)) { + checkModule(statement); + } + } + } + + return {}; + }, +}); + +function isDeclareGlobalOrExternalModuleDeclaration(node: ts.Node): boolean { + return ( + isModuleDeclaration(node) && + (node.name.kind === ts.SyntaxKind.StringLiteral || + (node.name.kind === ts.SyntaxKind.Identifier && node.name.text === "global")) + ); +} + +function isModuleDeclaration(node: ts.Node): node is ts.ModuleDeclaration { + return node.kind === ts.SyntaxKind.ModuleDeclaration; +} + +function isDeclare(node: ts.Node): boolean { + return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword); +} + +function isExport(node: ts.Node): boolean { + return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword); +} + +function isDefault(node: ts.Node): boolean { + return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword); +} + +// tslint:disable-next-line:max-line-length +// Copied from https://github.com/Microsoft/TypeScript/blob/dd9b8cab34a3e389e924d768eb656cf50656f582/src/compiler/binder.ts#L1571-L1581 +function hasExportDeclarations(node: ts.SourceFile | ts.ModuleDeclaration): boolean { + const body = node.kind === ts.SyntaxKind.SourceFile ? node : node.body; + if (body && (body.kind === ts.SyntaxKind.SourceFile || body.kind === ts.SyntaxKind.ModuleBlock)) { + for (const stat of (body as ts.BlockLike).statements) { + if (stat.kind === ts.SyntaxKind.ExportDeclaration || stat.kind === ts.SyntaxKind.ExportAssignment) { + return true; + } + } + } + return false; +} + +function isAutomaticExport(node: ts.SourceFile | ts.ModuleDeclaration): boolean { + // We'd like to just test ts.NodeFlags.ExportContext, but we don't run the + // binder, so that flag won't be set, so duplicate the logic instead. :( + // + // ts.NodeFlags.Ambient is @internal, but all modules that get here should + // be ambient. + return !hasExportDeclarations(node); +} + +export = rule; diff --git a/packages/dtslint/src/rules/strictExportDeclareModifiersRule.ts b/packages/dtslint/src/rules/strictExportDeclareModifiersRule.ts deleted file mode 100644 index a7f7e605b9..0000000000 --- a/packages/dtslint/src/rules/strictExportDeclareModifiersRule.ts +++ /dev/null @@ -1,173 +0,0 @@ -import * as Lint from "tslint"; -import * as ts from "typescript"; - -import { failure } from "../util"; - -export class Rule extends Lint.Rules.AbstractRule { - static metadata: Lint.IRuleMetadata = { - ruleName: "strict-export-declare-modifiers", - description: "Enforces strict rules about where the 'export' and 'declare' modifiers may appear.", - optionsDescription: "Not configurable.", - options: null, - type: "style", - typescriptOnly: true, - }; - - apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithFunction(sourceFile, walk); - } -} - -function walk(ctx: Lint.WalkContext): void { - const { sourceFile } = ctx; - const isExternal = - sourceFile.isDeclarationFile && - !sourceFile.statements.some( - (s) => - s.kind === ts.SyntaxKind.ExportAssignment || - (s.kind === ts.SyntaxKind.ExportDeclaration && !!(s as ts.ExportDeclaration).exportClause) - ) && - ts.isExternalModule(sourceFile); - - for (const node of sourceFile.statements) { - if (isExternal) { - checkInExternalModule(node, isAutomaticExport(sourceFile)); - } else { - checkInOther(node, sourceFile.isDeclarationFile); - } - - if (isModuleDeclaration(node) && (sourceFile.isDeclarationFile || isDeclare(node))) { - checkModule(node); - } - } - - function checkInExternalModule(node: ts.Statement, autoExportEnabled: boolean) { - // Ignore certain node kinds (these can't have 'export' or 'default' modifiers) - switch (node.kind) { - case ts.SyntaxKind.ImportDeclaration: - case ts.SyntaxKind.ImportEqualsDeclaration: - case ts.SyntaxKind.ExportDeclaration: - case ts.SyntaxKind.NamespaceExportDeclaration: - return; - } - - // `declare global` and `declare module "foo"` OK. `declare namespace N` not OK, should be `export namespace`. - if (!isDeclareGlobalOrExternalModuleDeclaration(node)) { - if (isDeclare(node)) { - fail(mod(node, ts.SyntaxKind.DeclareKeyword)!, "'declare' keyword is redundant here."); - } - if (autoExportEnabled && !isExport(node)) { - fail( - (node as ts.DeclarationStatement).name || node, - "All declarations in this module are exported automatically. " + - "Prefer to explicitly write 'export' for clarity. " + - "If you have a good reason not to export this declaration, " + - "add 'export {}' to the module to shut off automatic exporting." - ); - } - } - } - - function checkInOther(node: ts.Statement, inDeclarationFile: boolean): void { - // Compiler will enforce presence of 'declare' where necessary. But types do not need 'declare'. - if (isDeclare(node)) { - if ( - (isExport(node) && inDeclarationFile) || - node.kind === ts.SyntaxKind.InterfaceDeclaration || - node.kind === ts.SyntaxKind.TypeAliasDeclaration - ) { - fail(mod(node, ts.SyntaxKind.DeclareKeyword)!, "'declare' keyword is redundant here."); - } - } - } - - function fail(node: ts.Node, reason: string): void { - ctx.addFailureAtNode(node, failure(Rule.metadata.ruleName, reason)); - } - - function mod(node: ts.Statement, kind: ts.SyntaxKind): ts.Node | undefined { - return ts.canHaveModifiers(node) ? ts.getModifiers(node)?.find((m) => m.kind === kind) : undefined; - } - - function checkModule(moduleDeclaration: ts.ModuleDeclaration): void { - const body = moduleDeclaration.body; - if (!body) { - return; - } - - switch (body.kind) { - case ts.SyntaxKind.ModuleDeclaration: - checkModule(body); - break; - case ts.SyntaxKind.ModuleBlock: - checkBlock(body, isAutomaticExport(moduleDeclaration)); - break; - } - } - - function checkBlock(block: ts.ModuleBlock, autoExportEnabled: boolean): void { - for (const s of block.statements) { - // Compiler will error for 'declare' here anyway, so just check for 'export'. - if (isExport(s) && autoExportEnabled && !isDefault(s)) { - fail( - mod(s, ts.SyntaxKind.ExportKeyword)!, - "'export' keyword is redundant here because " + - "all declarations in this module are exported automatically. " + - "If you have a good reason to export some declarations and not others, " + - "add 'export {}' to the module to shut off automatic exporting." - ); - } - - if (isModuleDeclaration(s)) { - checkModule(s); - } - } - } -} - -function isDeclareGlobalOrExternalModuleDeclaration(node: ts.Node): boolean { - return ( - isModuleDeclaration(node) && - (node.name.kind === ts.SyntaxKind.StringLiteral || - (node.name.kind === ts.SyntaxKind.Identifier && node.name.text === "global")) - ); -} - -function isModuleDeclaration(node: ts.Node): node is ts.ModuleDeclaration { - return node.kind === ts.SyntaxKind.ModuleDeclaration; -} - -function isDeclare(node: ts.Node): boolean { - return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DeclareKeyword); -} - -function isExport(node: ts.Node): boolean { - return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword); -} - -function isDefault(node: ts.Node): boolean { - return ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword); -} - -// tslint:disable-next-line:max-line-length -// Copied from https://github.com/Microsoft/TypeScript/blob/dd9b8cab34a3e389e924d768eb656cf50656f582/src/compiler/binder.ts#L1571-L1581 -function hasExportDeclarations(node: ts.SourceFile | ts.ModuleDeclaration): boolean { - const body = node.kind === ts.SyntaxKind.SourceFile ? node : node.body; - if (body && (body.kind === ts.SyntaxKind.SourceFile || body.kind === ts.SyntaxKind.ModuleBlock)) { - for (const stat of (body as ts.BlockLike).statements) { - if (stat.kind === ts.SyntaxKind.ExportDeclaration || stat.kind === ts.SyntaxKind.ExportAssignment) { - return true; - } - } - } - return false; -} - -function isAutomaticExport(node: ts.SourceFile | ts.ModuleDeclaration): boolean { - // We'd like to just test ts.NodeFlags.ExportContext, but we don't run the - // binder, so that flag won't be set, so duplicate the logic instead. :( - // - // ts.NodeFlags.Ambient is @internal, but all modules that get here should - // be ambient. - return !hasExportDeclarations(node); -} diff --git a/packages/dtslint/test/strict-export-declare-modifiers.test.ts b/packages/dtslint/test/strict-export-declare-modifiers.test.ts new file mode 100644 index 0000000000..89f177ad27 --- /dev/null +++ b/packages/dtslint/test/strict-export-declare-modifiers.test.ts @@ -0,0 +1,158 @@ +import { ESLintUtils } from "@typescript-eslint/utils"; + +import * as strictExportDeclareModifiers from "../src/rules/strict-export-declare-modifiers"; + +const ruleTester = new ESLintUtils.RuleTester({ + parser: "@typescript-eslint/parser", +}); + +ruleTester.run("strict-export-declare-modifiers", strictExportDeclareModifiers, { + invalid: [ + { + code: `declare interface I {}`, + errors: [ + { + column: 1, + endColumn: 8, + line: 1, + messageId: "redundantDeclare", + }, + ], + }, + { + code: ` +declare namespace M { + export const x: number; +} + `, + errors: [ + { + column: 5, + endColumn: 11, + line: 3, + messageId: "redundantExport", + }, + ], + }, + { + code: `export declare function f(): void;`, + errors: [ + { + line: 1, + messageId: "redundantDeclare", + }, + ], + filename: "testModuleAutoExport.d.ts", + }, + { + code: ` +export namespace M { + export function f(): void; +} +`, + errors: [ + { + column: 3, + endColumn: 9, + line: 3, + messageId: "redundantExport", + }, + ], + filename: "testModuleAutoExport.d.ts", + }, + { + code: ` +interface I {} +export namespace M {} + `, + errors: [ + { + column: 11, + endColumn: 12, + line: 2, + messageId: "missingExplicitExport", + }, + ], + filename: "testModuleAutoExport.d.ts", + }, + { + code: ` +declare function g(): void; +export namespace M {} + `, + errors: [ + { + column: 1, + endColumn: 8, + line: 2, + messageId: "redundantDeclare", + }, + { + column: 18, + endColumn: 19, + line: 2, + messageId: "missingExplicitExport", + }, + ], + filename: "testModuleAutoExport.d.ts", + }, + { + code: ` +declare namespace N {} +export namespace M {} + `, + errors: [ + { + column: 1, + endColumn: 8, + line: 2, + messageId: "redundantDeclare", + }, + { + column: 19, + endColumn: 20, + line: 2, + messageId: "missingExplicitExport", + }, + ], + filename: "testModuleAutoExport.d.ts", + }, + ], + valid: [ + `export declare class C {}`, + `export function f() {}`, + `declare function g(): void;`, + `declare namespace N {};`, + `interface J {}`, + ` +namespace N { + export const x: number; +} + `, + { + code: ` +declare class Foo {} +export { Foo as Bar } + `, + filename: "./testValuesDeclareClass.d.ts", + }, + { + code: ` +import * as foo from "foo"; +import foo = require("foo"); +export { foo }; +export { foo } from "foo"; +export as namespace Foo; + `, + filename: "testModule.d.ts", + }, + { + code: ` +import * as foo from "foo"; +import foo = require("foo"); +export as namespace Foo; + `, + filename: "testModuleAutoExport.d.ts", + }, + ], +}); diff --git a/packages/dtslint/test/strict-export-declare-modifiers/testAmbient.d.ts.lint b/packages/dtslint/test/strict-export-declare-modifiers/testAmbient.d.ts.lint deleted file mode 100644 index bf38d8c8ad..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/testAmbient.d.ts.lint +++ /dev/null @@ -1,24 +0,0 @@ -declare function f(): void; - -declare type T = number; -~~~~~~~ [declare-redundant] - -declare interface I {} -~~~~~~~ [declare-redundant] - -declare module "m" { - export function f(): void; - ~~~~~~ [export-redundant] - function g(): void; - export default function h(); -} - -declare module "m2" { - export {}; - export function f(): void; - function g(): void; -} - - -[declare-redundant]: 'declare' keyword is redundant here. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md -[export-redundant]: 'export' keyword is redundant here because all declarations in this module are exported automatically. If you have a good reason to export some declarations and not others, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md diff --git a/packages/dtslint/test/strict-export-declare-modifiers/testModule.d.ts.lint b/packages/dtslint/test/strict-export-declare-modifiers/testModule.d.ts.lint deleted file mode 100644 index 5572fa16fe..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/testModule.d.ts.lint +++ /dev/null @@ -1,23 +0,0 @@ -import * as foo from "foo"; -import foo = require("foo"); -export { foo }; -export { foo } from "foo"; -export as namespace Foo; - -interface I {} - -export declare function f(): void; - ~~~~~~~ [declare-redundant] - -declare function g(): void; - -declare namespace N {} - -export namespace M { - export function f(): void; - ~~~~~~ [export-redundant] - // TS compiler warns for 'declare' here. -} - -[declare-redundant]: 'declare' keyword is redundant here. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md -[export-redundant]: 'export' keyword is redundant here because all declarations in this module are exported automatically. If you have a good reason to export some declarations and not others, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md diff --git a/packages/dtslint/test/strict-export-declare-modifiers/testModuleAutoExport.d.ts.lint b/packages/dtslint/test/strict-export-declare-modifiers/testModuleAutoExport.d.ts.lint deleted file mode 100644 index 8f78c74343..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/testModuleAutoExport.d.ts.lint +++ /dev/null @@ -1,27 +0,0 @@ -import * as foo from "foo"; -import foo = require("foo"); -export as namespace Foo; - -interface I {} - ~ [export-preferred] - -export declare function f(): void; - ~~~~~~~ [declare] - -declare function g(): void; -~~~~~~~ [declare] - ~ [export-preferred] - -declare namespace N {} -~~~~~~~ [declare] - ~ [export-preferred] - -export namespace M { - export function f(): void; - ~~~~~~ [export-redundant] - // TS compiler warns for 'declare' here. -} - -[declare]: 'declare' keyword is redundant here. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md -[export-preferred]: All declarations in this module are exported automatically. Prefer to explicitly write 'export' for clarity. If you have a good reason not to export this declaration, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md -[export-redundant]: 'export' keyword is redundant here because all declarations in this module are exported automatically. If you have a good reason to export some declarations and not others, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md diff --git a/packages/dtslint/test/strict-export-declare-modifiers/testModuleTs.ts.lint b/packages/dtslint/test/strict-export-declare-modifiers/testModuleTs.ts.lint deleted file mode 100644 index 621997b2bb..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/testModuleTs.ts.lint +++ /dev/null @@ -1,20 +0,0 @@ -export declare class C {} - -export function f() {} - -declare interface I {} -~~~~~~~ [declare-redundant] - -interface J {} - -namespace N { - export const x: number; -} - -declare namespace M { - export const x: number; - ~~~~~~ [export-redundant] -} - -[declare-redundant]: 'declare' keyword is redundant here. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md -[export-redundant]: 'export' keyword is redundant here because all declarations in this module are exported automatically. If you have a good reason to export some declarations and not others, add 'export {}' to the module to shut off automatic exporting. See: https://github.com/microsoft/DefinitelyTyped-tools/blob/master/packages/dtslint/docs/strict-export-declare-modifiers.md diff --git a/packages/dtslint/test/strict-export-declare-modifiers/testValues.d.ts.lint b/packages/dtslint/test/strict-export-declare-modifiers/testValues.d.ts.lint deleted file mode 100644 index 1015779d31..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/testValues.d.ts.lint +++ /dev/null @@ -1,2 +0,0 @@ -declare class Foo {} -export { Foo as Bar } \ No newline at end of file diff --git a/packages/dtslint/test/strict-export-declare-modifiers/tslint.json b/packages/dtslint/test/strict-export-declare-modifiers/tslint.json deleted file mode 100644 index ee7a94ac3c..0000000000 --- a/packages/dtslint/test/strict-export-declare-modifiers/tslint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rulesDirectory": ["../../dist/rules"], - "rules": { - "strict-export-declare-modifiers": true - } -} From bc41c01ad5f535d938c11d9ded6a6542e4e6d5e2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:23:25 -0700 Subject: [PATCH 2/3] Add rule to rule list --- packages/eslint-plugin/src/rules/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-plugin/src/rules/index.ts b/packages/eslint-plugin/src/rules/index.ts index b18499e465..7efc50f92a 100644 --- a/packages/eslint-plugin/src/rules/index.ts +++ b/packages/eslint-plugin/src/rules/index.ts @@ -14,6 +14,7 @@ import * as noUnnecessaryGenerics from "./no-unnecessary-generics"; import * as noUselessFiles from "./no-useless-files"; import * as preferDeclareFunction from "./prefer-declare-function"; import * as redundantUndefined from "./redundant-undefined"; +import * as strictExportDeclareModifiers from "./strict-export-declare-modifiers"; export const rules = { "dt-header": dtHeader, @@ -32,4 +33,5 @@ export const rules = { "no-useless-files": noUselessFiles, "prefer-declare-function": preferDeclareFunction, "redundant-undefined": redundantUndefined, + "strict-export-declare-modifiers": strictExportDeclareModifiers, }; From 269740b10af1970ec08625d4dbd6e0397edf1e7a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:08:29 -0700 Subject: [PATCH 3/3] Add changeset to ship these changes --- .changeset/lucky-dolphins-raise.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/lucky-dolphins-raise.md diff --git a/.changeset/lucky-dolphins-raise.md b/.changeset/lucky-dolphins-raise.md new file mode 100644 index 0000000000..3aa32b8dc7 --- /dev/null +++ b/.changeset/lucky-dolphins-raise.md @@ -0,0 +1,6 @@ +--- +"@definitelytyped/eslint-plugin": patch +"@definitelytyped/dtslint": patch +--- + +Port strict-export-declare-modifiers tslint->eslint