From 1f499884d034ca96ccb99127267ef58f552402c9 Mon Sep 17 00:00:00 2001 From: Kai Nguyen Date: Wed, 30 Oct 2024 16:22:48 +1100 Subject: [PATCH] MI-72: Update template to use new eslint --- eslint.config.mjs | 3 +-- tools/serverless-plugin/project.json | 2 +- .../service/general-files/.eslintrc.json.template | 4 ---- .../service/general-files/eslint.config.mjs.template | 3 +++ .../general-files/tests/example-tests.test.ts.template | 2 +- .../service/general-files/tsconfig.json.template | 1 - .../service/general-files/vite.config.mjs.template | 2 +- .../src/generators/service/generator.ts | 7 +------ .../service/notification-files/.eslintrc.json.template | 4 ---- .../generators/service/notification-files/README.md | 10 +++++----- .../notification-files/eslint.config.mjs.template | 3 +++ .../service/notification-files/tsconfig.json.template | 1 - .../notification-files/vite.config.mjs.template | 2 +- tsconfig.base.json | 4 +--- 14 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 tools/serverless-plugin/src/generators/service/general-files/.eslintrc.json.template create mode 100644 tools/serverless-plugin/src/generators/service/general-files/eslint.config.mjs.template delete mode 100644 tools/serverless-plugin/src/generators/service/notification-files/.eslintrc.json.template create mode 100644 tools/serverless-plugin/src/generators/service/notification-files/eslint.config.mjs.template diff --git a/eslint.config.mjs b/eslint.config.mjs index c7b3ffe6..58f136ab 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -6,7 +6,7 @@ import nxEslintPlugin from '@nx/eslint-plugin'; export const eslintBaseConfig = [ ...eslintConfigs.core, { - files: ['**/*.ts', '**/*.tsx'], + files: ['**/*.ts'], plugins: { '@nx': nxEslintPlugin, import: eslintPluginImport, @@ -38,7 +38,6 @@ export const eslintBaseConfig = [ }, { files: ['**/*.json'], - rules: {}, languageOptions: { parser: jsonParser }, }, ]; diff --git a/tools/serverless-plugin/project.json b/tools/serverless-plugin/project.json index b657d873..bdef0b32 100644 --- a/tools/serverless-plugin/project.json +++ b/tools/serverless-plugin/project.json @@ -29,7 +29,7 @@ "options": { "cwd": "{projectRoot}", "color": true, - "command": "eslint ." + "command": "eslint . --max-warnings 0" } }, "test": { diff --git a/tools/serverless-plugin/src/generators/service/general-files/.eslintrc.json.template b/tools/serverless-plugin/src/generators/service/general-files/.eslintrc.json.template deleted file mode 100644 index e1fe69ad..00000000 --- a/tools/serverless-plugin/src/generators/service/general-files/.eslintrc.json.template +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"] -} diff --git a/tools/serverless-plugin/src/generators/service/general-files/eslint.config.mjs.template b/tools/serverless-plugin/src/generators/service/general-files/eslint.config.mjs.template new file mode 100644 index 00000000..74f9ce00 --- /dev/null +++ b/tools/serverless-plugin/src/generators/service/general-files/eslint.config.mjs.template @@ -0,0 +1,3 @@ +import { eslintBaseConfig } from '../../eslint.config.mjs'; + +export default [...eslintBaseConfig, { ignores: ['!./**/*.ts'] }]; diff --git a/tools/serverless-plugin/src/generators/service/general-files/tests/example-tests.test.ts.template b/tools/serverless-plugin/src/generators/service/general-files/tests/example-tests.test.ts.template index 0dbc8f88..95fa6586 100644 --- a/tools/serverless-plugin/src/generators/service/general-files/tests/example-tests.test.ts.template +++ b/tools/serverless-plugin/src/generators/service/general-files/tests/example-tests.test.ts.template @@ -1,4 +1,4 @@ -import { simpleObject, YOUR_ENV_VAR } from './__data__/example-data'; +import { YOUR_ENV_VAR, simpleObject } from './__data__/example-data'; describe('Passing tests', () => { test('Passing test', () => { diff --git a/tools/serverless-plugin/src/generators/service/general-files/tsconfig.json.template b/tools/serverless-plugin/src/generators/service/general-files/tsconfig.json.template index cc611d63..6327ee95 100644 --- a/tools/serverless-plugin/src/generators/service/general-files/tsconfig.json.template +++ b/tools/serverless-plugin/src/generators/service/general-files/tsconfig.json.template @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.base.json", "include": [ - "vite.config.mjs", "../../libs/**/src/index.ts", "src/**/*.ts", "**/*.test.ts" diff --git a/tools/serverless-plugin/src/generators/service/general-files/vite.config.mjs.template b/tools/serverless-plugin/src/generators/service/general-files/vite.config.mjs.template index bfb64717..9d8d7176 100644 --- a/tools/serverless-plugin/src/generators/service/general-files/vite.config.mjs.template +++ b/tools/serverless-plugin/src/generators/service/general-files/vite.config.mjs.template @@ -1,5 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; -import { viteBaseConfig } from '../../vite.config.base.mjs'; +import { viteBaseConfig } from '../../vite.config.mjs'; export default mergeConfig( viteBaseConfig, diff --git a/tools/serverless-plugin/src/generators/service/generator.ts b/tools/serverless-plugin/src/generators/service/generator.ts index 958bb619..6cd8e749 100644 --- a/tools/serverless-plugin/src/generators/service/generator.ts +++ b/tools/serverless-plugin/src/generators/service/generator.ts @@ -41,12 +41,7 @@ export async function serviceGenerator(tree: Tree, options: serviceGeneratorSche ...buildRunCommandConfig('tsc --noEmit --pretty'), }, lint: { - executor: '@nx/eslint:lint', - outputs: ['{options.outputFile}'], - options: { - lintFilePatterns: [projectRoot + '/**/*.ts'], - maxWarnings: 0, - }, + ...buildRunCommandConfig('eslint . --max-warnings 0'), }, test: { executor: '@nx/vite:test', diff --git a/tools/serverless-plugin/src/generators/service/notification-files/.eslintrc.json.template b/tools/serverless-plugin/src/generators/service/notification-files/.eslintrc.json.template deleted file mode 100644 index e1fe69ad..00000000 --- a/tools/serverless-plugin/src/generators/service/notification-files/.eslintrc.json.template +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"] -} diff --git a/tools/serverless-plugin/src/generators/service/notification-files/README.md b/tools/serverless-plugin/src/generators/service/notification-files/README.md index 46a10523..b734d64f 100644 --- a/tools/serverless-plugin/src/generators/service/notification-files/README.md +++ b/tools/serverless-plugin/src/generators/service/notification-files/README.md @@ -56,15 +56,15 @@ This service accepts events in the following format (similar to CloudWatch Event "time": "2024-06-24T04:42:33.884Z", "region": "ap-southeast-2", "resources": [ - "arn:aws:lambda:ap-southeast-2:XXXXXXXXXX:function:tt-int-shippit-order-dev-lambdaName" + "arn:aws:lambda:ap-southeast-2:XXXXXXXXXX:function:client-int-service-name-stg-lambdaName" ], "detail": { - "executionArn": "arn:aws:lambda:ap-southeast-2:XXXXXXXXXX:function:tt-int-shippit-order-dev-lambdaName", - "logGroupName": "/aws/lambda/tt-int-shippit-order-dev-lambdaName", - "name": "tt-int-shippit-order-dev-lambdaName", + "executionArn": "arn:aws:lambda:ap-southeast-2:XXXXXXXXXX:function:client-int-service-name-stg-lambdaName", + "logGroupName": "/aws/lambda/client-int-service-name-stg-lambdaName", + "name": "client-int-service-name-stg-lambdaName", "status": "FAILED", "error": "SyntaxError", - "cause": "{\"errorType\":\"SyntaxError\",\"errorMessage\":\"Unexpected token u in JSON at position 0\",\"trace\":\"SyntaxError: Unexpected token u in JSON at position 0\\n at JSON.parse ()\\n at Runtime.V1 (/src/lambda/create-shippit-order.ts:39:34)\\n at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)\"}" + "cause": "{\"errorType\":\"SyntaxError\",\"errorMessage\":\"Unexpected token u in JSON at position 0\",\"trace\":\"SyntaxError: Unexpected token u in JSON at position 0\\n at JSON.parse ()\\n at Runtime.V1 (/src/lambda/create-order.ts:39:34)\\n at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)\"}" } } ``` diff --git a/tools/serverless-plugin/src/generators/service/notification-files/eslint.config.mjs.template b/tools/serverless-plugin/src/generators/service/notification-files/eslint.config.mjs.template new file mode 100644 index 00000000..74f9ce00 --- /dev/null +++ b/tools/serverless-plugin/src/generators/service/notification-files/eslint.config.mjs.template @@ -0,0 +1,3 @@ +import { eslintBaseConfig } from '../../eslint.config.mjs'; + +export default [...eslintBaseConfig, { ignores: ['!./**/*.ts'] }]; diff --git a/tools/serverless-plugin/src/generators/service/notification-files/tsconfig.json.template b/tools/serverless-plugin/src/generators/service/notification-files/tsconfig.json.template index cc611d63..6327ee95 100644 --- a/tools/serverless-plugin/src/generators/service/notification-files/tsconfig.json.template +++ b/tools/serverless-plugin/src/generators/service/notification-files/tsconfig.json.template @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.base.json", "include": [ - "vite.config.mjs", "../../libs/**/src/index.ts", "src/**/*.ts", "**/*.test.ts" diff --git a/tools/serverless-plugin/src/generators/service/notification-files/vite.config.mjs.template b/tools/serverless-plugin/src/generators/service/notification-files/vite.config.mjs.template index e4cb915c..3ef375e6 100644 --- a/tools/serverless-plugin/src/generators/service/notification-files/vite.config.mjs.template +++ b/tools/serverless-plugin/src/generators/service/notification-files/vite.config.mjs.template @@ -1,5 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; -import { viteBaseConfig } from '../../vite.config.base.mjs'; +import { viteBaseConfig } from '../../vite.config.mjs'; export default mergeConfig( viteBaseConfig, diff --git a/tsconfig.base.json b/tsconfig.base.json index d4ebe8e9..ef2c8363 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -7,9 +7,7 @@ "exactOptionalPropertyTypes": false, "noUncheckedSideEffectImports": true, "paths": { - "@aligent/serverless-plugin": [ - "tools/serverless-plugin/src/index.ts" - ] + "@aligent/serverless-plugin": ["tools/serverless-plugin/src/index.ts"] }, "types": ["node", "vitest", "vitest/globals"] }