From 16ff20c70fa9a7e39fa0c77c6a5c7cdace364a96 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Mon, 25 Sep 2023 11:12:07 +0200 Subject: [PATCH] fix: correct build configuration for ESLint plugin --- packages/eslint-plugin/package.json | 2 +- .../src/rules/ccapi-validate-args.ts | 8 ++++++-- .../src/rules/no-debug-in-tests.ts | 4 ++-- .../src/rules/no-forbidden-imports.ts | 3 ++- packages/eslint-plugin/src/utils.ts | 8 +++++++- packages/eslint-plugin/tsconfig.build.json | 19 +++++++++++++++++++ packages/eslint-plugin/tsconfig.json | 18 ++++++++++-------- 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 packages/eslint-plugin/tsconfig.build.json diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 418e04594137..2587d5dec30e 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -28,7 +28,7 @@ "node": ">= 18" }, "scripts": { - "build": "tsc -b tsconfig.json --pretty", + "build": "tsc -b tsconfig.build.json --pretty", "clean": "del-cli build/ \"*.tsbuildinfo\"", "lint:ts": "eslint --cache --ext .ts \"src/**/*.ts\"", "lint:ts:fix": "yarn run lint:ts --fix" diff --git a/packages/eslint-plugin/src/rules/ccapi-validate-args.ts b/packages/eslint-plugin/src/rules/ccapi-validate-args.ts index 6a597f216b7f..e3a9e0414891 100644 --- a/packages/eslint-plugin/src/rules/ccapi-validate-args.ts +++ b/packages/eslint-plugin/src/rules/ccapi-validate-args.ts @@ -3,11 +3,15 @@ import { AST_TOKEN_TYPES, ESLintUtils, } from "@typescript-eslint/utils"; -import { findDecoratorContainingCCId, getCCNameFromDecorator } from "../utils"; +import { + type Rule, + findDecoratorContainingCCId, + getCCNameFromDecorator, +} from "../utils"; const isFixMode = process.argv.some((arg) => arg.startsWith("--fix")); -export const ccAPIValidateArgs = ESLintUtils.RuleCreator.withoutDocs({ +export const ccAPIValidateArgs: Rule = ESLintUtils.RuleCreator.withoutDocs({ create(context) { let currentAPIClassCCName: string | undefined; let validateArgsImport: string | undefined; diff --git a/packages/eslint-plugin/src/rules/no-debug-in-tests.ts b/packages/eslint-plugin/src/rules/no-debug-in-tests.ts index ea0b7578fc20..3079cdd2d23b 100644 --- a/packages/eslint-plugin/src/rules/no-debug-in-tests.ts +++ b/packages/eslint-plugin/src/rules/no-debug-in-tests.ts @@ -1,6 +1,6 @@ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils"; import path from "node:path"; -import { repoRoot } from "../utils.js"; +import { type Rule, repoRoot } from "../utils.js"; const isFixMode = process.argv.some((arg) => arg.startsWith("--fix")); @@ -20,7 +20,7 @@ const integrationTestExportNames = new Set([ "integrationTest", ]); -export const noDebugInTests = ESLintUtils.RuleCreator.withoutDocs({ +export const noDebugInTests: Rule = ESLintUtils.RuleCreator.withoutDocs({ create(context) { const integrationTestMethodNames = new Set(); diff --git a/packages/eslint-plugin/src/rules/no-forbidden-imports.ts b/packages/eslint-plugin/src/rules/no-forbidden-imports.ts index cd6432dc30ff..f199fe45a980 100644 --- a/packages/eslint-plugin/src/rules/no-forbidden-imports.ts +++ b/packages/eslint-plugin/src/rules/no-forbidden-imports.ts @@ -2,6 +2,7 @@ import { ESLintUtils, type TSESTree } from "@typescript-eslint/utils"; import fs from "node:fs"; import path from "node:path"; import ts from "typescript"; +import { type Rule } from "../utils"; // Whitelist some imports that are known not to import forbidden modules const whitelistedImports = [ @@ -185,7 +186,7 @@ function resolveSourceFileFromDefinition( const forbiddenImportsRegex = /^@forbiddenImports (?.*?)$/; -export const noForbiddenImports = ESLintUtils.RuleCreator.withoutDocs({ +export const noForbiddenImports: Rule = ESLintUtils.RuleCreator.withoutDocs({ create(context) { // And only those with at least one /* @forbiddenImports ... */ comment const comments = context.sourceCode.getAllComments() diff --git a/packages/eslint-plugin/src/utils.ts b/packages/eslint-plugin/src/utils.ts index 40950d5c5396..a01df216c469 100644 --- a/packages/eslint-plugin/src/utils.ts +++ b/packages/eslint-plugin/src/utils.ts @@ -1,4 +1,8 @@ -import { AST_NODE_TYPES, type TSESTree } from "@typescript-eslint/utils"; +import { + AST_NODE_TYPES, + type TSESLint, + type TSESTree, +} from "@typescript-eslint/utils"; import { CommandClasses } from "@zwave-js/core"; import path from "node:path"; @@ -88,3 +92,5 @@ export function getCCIdFromDecorator( ): CommandClasses { return (CommandClasses as any)[getCCNameFromDecorator(decorator)]; } + +export type Rule = TSESLint.RuleModule; diff --git a/packages/eslint-plugin/tsconfig.build.json b/packages/eslint-plugin/tsconfig.build.json new file mode 100644 index 000000000000..e54d3c136fac --- /dev/null +++ b/packages/eslint-plugin/tsconfig.build.json @@ -0,0 +1,19 @@ +// tsconfig for building - only applies to the src directory +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + { + "path": "../core/tsconfig.build.json" + } + ], + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "src/**/*.test.ts" + ] +} diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json index 565e47022054..009cf5cd263f 100644 --- a/packages/eslint-plugin/tsconfig.json +++ b/packages/eslint-plugin/tsconfig.json @@ -1,17 +1,19 @@ +// tsconfig for IntelliSense - active in all files in the current package { - "extends": "@tsconfig/node18/tsconfig.json", + "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "src", - "outDir": "build", - "incremental": true, - "sourceMap": true + "types": ["node", "@typescript-eslint/utils"] }, - "include": [ - "src/**/*.ts" - ], "references": [ { "path": "../core" } + ], + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "build/**", + "node_modules/**" ] }