diff --git a/.projenrc.ts b/.projenrc.ts index beb10fa36..2f441a96f 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -699,6 +699,17 @@ const cli = configureProject( }), ); +// Eslint rules +cli.eslint?.addRules({ + '@cdklabs/no-throw-default-error': ['error'], +}); +cli.eslint?.addOverride({ + files: ["./test/**"], + rules: { + "@cdklabs/no-throw-default-error": "off", + }, +}); + // Do include all .ts files inside init-templates cli.npmignore?.addPatterns('!lib/init-templates/**/*.ts'); @@ -988,6 +999,24 @@ const toolkitLib = configureProject( }), ); +// Eslint rules +toolkitLib.eslint?.addRules({ + '@cdklabs/no-throw-default-error': ['error'], + 'import/no-restricted-paths': ['error', { + zones: [{ + target: './', + from: '../../aws-cdk', + message: "All `aws-cdk` code must be used via lib/api/aws-cdk.ts", + }] + }], +}); +toolkitLib.eslint?.addOverride({ + files: ["./test/**"], + rules: { + "@cdklabs/no-throw-default-error": "off", + }, +}); + // Prevent imports of private API surface toolkitLib.package.addField("exports", { ".": { diff --git a/packages/@aws-cdk/toolkit/.eslintrc.json b/packages/@aws-cdk/toolkit/.eslintrc.json index 0d81153b4..7306062cb 100644 --- a/packages/@aws-cdk/toolkit/.eslintrc.json +++ b/packages/@aws-cdk/toolkit/.eslintrc.json @@ -261,7 +261,31 @@ "jest/no-focused-tests": "error", "prettier/prettier": [ "off" + ], + "@cdklabs/no-throw-default-error": [ + "error" + ], + "import/no-restricted-paths": [ + "error", + { + "zones": [ + { + "target": "./", + "from": "../../aws-cdk", + "message": "All `aws-cdk` code must be used via lib/api/aws-cdk.ts" + } + ] + } ] }, - "overrides": [] + "overrides": [ + { + "files": [ + "./test/**" + ], + "rules": { + "@cdklabs/no-throw-default-error": "off" + } + } + ] } diff --git a/packages/aws-cdk/.eslintrc.json b/packages/aws-cdk/.eslintrc.json index ebd5fabe2..514e784f5 100644 --- a/packages/aws-cdk/.eslintrc.json +++ b/packages/aws-cdk/.eslintrc.json @@ -262,7 +262,19 @@ "jest/no-focused-tests": "error", "prettier/prettier": [ "off" + ], + "@cdklabs/no-throw-default-error": [ + "error" ] }, - "overrides": [] + "overrides": [ + { + "files": [ + "./test/**" + ], + "rules": { + "@cdklabs/no-throw-default-error": "off" + } + } + ] } diff --git a/projenrc/eslint.ts b/projenrc/eslint.ts index 60c996da4..b867733f2 100644 --- a/projenrc/eslint.ts +++ b/projenrc/eslint.ts @@ -1,4 +1,3 @@ - export const ESLINT_RULES = { '@cdklabs/no-core-construct': ['error'], '@cdklabs/invalid-cfn-imports': ['error'], @@ -177,4 +176,4 @@ export const ESLINT_RULES = { "jest/no-identical-title": "off", // TEMPORARY - Disabling this until https://github.com/jest-community/eslint-plugin-jest/issues/836 is resolved 'jest/no-disabled-tests': 'error', // Skipped tests are easily missed in PR reviews 'jest/no-focused-tests': 'error', // Focused tests are easily missed in PR reviews -}; \ No newline at end of file +};