Skip to content

Commit 182b2b2

Browse files
authored
Improve code quality checks (#215)
1 parent 24f5db2 commit 182b2b2

File tree

9 files changed

+50
-77
lines changed

9 files changed

+50
-77
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
npm run benchmark -- \
3838
--templates tst/resources/templates/*.json tst/resources/templates/*.yaml \
3939
--output benchmark-results.md \
40-
--iterations 5000
40+
--iterations 2500
4141
4242
- name: Generate timestamp
4343
id: timestamp

.github/workflows/pr.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name: Pull Request
22

33
on:
44
pull_request:
5+
types: [opened, edited, reopened, synchronize]
56
branches: [ main ]
67

78
jobs:
89
get-configs:
910
uses: ./.github/workflows/configs.yml
1011

1112
pr-build-test-nodejs:
12-
needs: [get-configs]
13+
needs: [ get-configs ]
1314
runs-on: ubuntu-latest
1415
permissions:
1516
contents: read
@@ -29,11 +30,14 @@ jobs:
2930
- name: Build
3031
run: npm run build
3132

32-
- name: Lint and Test
33-
run: npm run lint && npm run test
33+
- name: Code Quality
34+
run: npm run lint && npm run check:duplicates
35+
36+
- name: Test
37+
run: npm run test
3438

3539
pr-build-test-go:
36-
needs: [get-configs]
40+
needs: [ get-configs ]
3741
runs-on: ubuntu-latest
3842
steps:
3943
- uses: actions/checkout@v5

.jscpd.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"src"
1616
],
1717
"gitignore": true,
18-
"threshold": 1,
18+
"threshold": 0.8,
1919
"minLines": 10,
2020
"output": "./jscpd",
2121
"reporters": [

src/auth/AwsSdkCredentialsProvider.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/services/CodeActionService.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { SyntaxTreeManager } from '../context/syntaxtree/SyntaxTreeManager';
1515
import { NodeSearch } from '../context/syntaxtree/utils/NodeSearch';
1616
import { NodeType } from '../context/syntaxtree/utils/NodeType';
1717
import { DocumentManager } from '../document/DocumentManager';
18-
import { ANALYZE_DIAGNOSTIC, TRACK_CODE_ACTION_ACCEPTED } from '../handlers/ExecutionHandler';
18+
import { TRACK_CODE_ACTION_ACCEPTED } from '../handlers/ExecutionHandler';
1919
import { CfnInfraCore } from '../server/CfnInfraCore';
2020
import { CFN_VALIDATION_SOURCE } from '../stacks/actions/ValidationWorkflow';
2121
import { LoggerFactory } from '../telemetry/LoggerFactory';
@@ -69,10 +69,6 @@ export class CodeActionService {
6969
}
7070
}
7171

72-
if (params.context.diagnostics.length > 0) {
73-
codeActions.push(this.generateAIAnalysisAction(params.textDocument.uri, params.context.diagnostics));
74-
}
75-
7672
if (this.shouldOfferRefactorActions(params)) {
7773
const refactorActions = this.generateRefactorActions(params);
7874
codeActions.push(...refactorActions);
@@ -107,19 +103,6 @@ export class CodeActionService {
107103
return fixes;
108104
}
109105

110-
private generateAIAnalysisAction(uri: string, diagnostics: Diagnostic[]): CodeAction {
111-
return {
112-
title: 'Ask AI',
113-
kind: 'quickfix',
114-
diagnostics,
115-
command: {
116-
title: 'Ask AI',
117-
command: ANALYZE_DIAGNOSTIC,
118-
arguments: [uri, diagnostics],
119-
},
120-
};
121-
}
122-
123106
/**
124107
* Generate fixes for CFN Validation diagnostics
125108
*/

tst/unit/services/CodeActionService.test.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,10 @@ describe('CodeActionService', () => {
3333
});
3434

3535
function verifyCodeAction(params: CodeActionParams, actual: CodeAction[], ...expected: CodeAction[]) {
36-
expect(actual.length).toBe(expected.length + 1);
36+
expect(actual.length).toBe(expected.length);
3737
for (const [index, expectedAction] of expected.entries()) {
3838
expect(equal(actual[index], expectedAction)).toBe(true);
3939
}
40-
41-
expect(
42-
equal(actual[actual.length - 1], {
43-
title: 'Ask AI',
44-
kind: 'quickfix',
45-
diagnostics: params.context.diagnostics,
46-
command: {
47-
title: 'Ask AI',
48-
command: '/command/llm/diagnostic/analyze',
49-
arguments: [params.textDocument.uri, params.context.diagnostics],
50-
},
51-
}),
52-
).toBe(true);
5340
}
5441

5542
describe('generateCodeActions', () => {

vitest.config.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import { defineConfig } from 'vitest/config';
22

33
export default defineConfig({
4-
test: {
5-
globals: true,
6-
environment: 'node',
7-
include: ['tst/**/*.test.ts'],
8-
exclude: ['**/node_modules/**', '**/out/**'],
9-
setupFiles: ['tst/setup.ts'],
10-
coverage: {
11-
provider: 'v8',
12-
reporter: ['cobertura', 'html', 'text'],
13-
include: ['src/**/*.{js,ts}'],
14-
enabled: true,
4+
test: {
5+
globals: true,
6+
environment: 'node',
7+
include: ['tst/**/*.test.ts'],
8+
exclude: ['**/node_modules/**', '**/out/**'],
9+
setupFiles: ['tst/setup.ts'],
10+
coverage: {
11+
provider: 'v8',
12+
reporter: ['cobertura', 'html', 'text'],
13+
include: ['src/**/*.{js,ts}'],
14+
enabled: true,
15+
thresholds: {
16+
statements: 85,
17+
branches: 85,
18+
functions: 85,
19+
lines: 85,
20+
},
21+
exclude: [
22+
'src/ai/**',
23+
'src/services/cfnLint/pyodide-worker.ts',
24+
'src/telemetry/OTELInstrumentation.ts',
25+
'src/telemetry/TelemetryService.ts',
26+
'src/services/guard/assets/**',
27+
],
28+
},
29+
pool: 'forks', // Run tests in separate processes for better isolation
30+
isolate: true, // Ensure each test file runs in isolation
31+
testTimeout: 30000, // Increase timeout for longer-running tests
1532
},
16-
pool: 'forks', // Run tests in separate processes for better isolation
17-
isolate: true, // Ensure each test file runs in isolation
18-
testTimeout: 30000, // Increase timeout for longer-running tests
19-
},
2033
});

vitest.integration.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { defineConfig } from 'vitest/config';
22
import baseConfig from './vitest.config';
33

44
export default defineConfig({
5-
...baseConfig,
6-
test: {
7-
...baseConfig.test,
8-
include: ['tst/integration/**/*.test.ts', 'tst/e2e/**/*.test.ts'],
9-
},
5+
...baseConfig,
6+
test: {
7+
...baseConfig.test,
8+
include: ['tst/integration/**/*.test.ts', 'tst/e2e/**/*.test.ts'],
9+
},
1010
});

vitest.unit.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { defineConfig } from 'vitest/config';
22
import baseConfig from './vitest.config';
33

44
export default defineConfig({
5-
...baseConfig,
6-
test: {
7-
...baseConfig.test,
8-
include: ['tst/unit/**/*.test.ts'],
9-
},
5+
...baseConfig,
6+
test: {
7+
...baseConfig.test,
8+
include: ['tst/unit/**/*.test.ts'],
9+
},
1010
});

0 commit comments

Comments
 (0)