Skip to content

Commit 754a3e6

Browse files
authored
Feature request: Add a trailing comma to generated tsconfig.json (microsoft#502)
1 parent 721aa9f commit 754a3e6

File tree

8 files changed

+20
-41
lines changed

8 files changed

+20
-41
lines changed

generators/app/templates/ext-command-ts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"sourceMap": true,
1010
"rootDir": "src",
11-
"strict": true /* enable all strict type-checking options */
11+
"strict": true, /* enable all strict type-checking options */
1212
/* Additional Checks */
1313
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1414
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

generators/app/templates/ext-command-ts/vscode-esbuild/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"sourceMap": true,
99
"rootDir": "src",
10-
"strict": true /* enable all strict type-checking options */
10+
"strict": true, /* enable all strict type-checking options */
1111
/* Additional Checks */
1212
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1313
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

generators/app/templates/ext-command-ts/vscode-webpack/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"sourceMap": true,
99
"rootDir": "src",
10-
"strict": true /* enable all strict type-checking options */
10+
"strict": true, /* enable all strict type-checking options */
1111
/* Additional Checks */
1212
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1313
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

generators/app/templates/ext-command-web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"sourceMap": true,
1010
"rootDir": "src",
11-
"strict": true /* enable all strict type-checking options */
11+
"strict": true, /* enable all strict type-checking options */
1212
/* Additional Checks */
1313
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1414
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

generators/app/templates/ext-notebook-renderer/src/tsconfig-base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"types": ["node"],
99
"sourceMap": true,
10-
"strict": true /* enable all strict type-checking options */
10+
"strict": true, /* enable all strict type-checking options */
1111
/* Additional Checks */
1212
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
1313
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"@types/node": "^18.19.57",
4848
"mocha": "^10.7.3",
4949
"yeoman-environment": "^4.4.3",
50-
"yeoman-test": "^10.0.1"
50+
"yeoman-test": "^10.0.1",
51+
"jsonc-parser": "^3.3.1"
5152
}
5253
}

test/test.mjs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,9 @@
44

55
import * as path from 'path';
66
import { fileURLToPath } from 'url';
7-
import { RunResult, createHelpers } from 'yeoman-test';
7+
import { createHelpers } from 'yeoman-test';
8+
import { parse } from 'jsonc-parser';
89
import * as env from '../generators/app/env.js';
9-
import { cwd } from 'process';
10-
11-
function stripComments(content) {
12-
/**
13-
* First capturing group matches double quoted string
14-
* Second matches single quotes string
15-
* Third matches block comments
16-
* Fourth matches line comments
17-
*/
18-
const regexp = /("(?:[^\\\"]*(?:\\.)?)*")|('(?:[^\\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g;
19-
const result = content.replace(regexp, (match, m1, m2, m3, m4) => {
20-
// Only one of m1, m2, m3, m4 matches
21-
if (m3) {
22-
// A block comment. Replace with nothing
23-
return '';
24-
} else if (m4) {
25-
// A line comment. If it ends in \r?\n then keep it.
26-
const length = m4.length;
27-
if (length > 2 && m4[length - 1] === '\n') {
28-
return m4[length - 2] === '\r' ? '\r\n' : '\n';
29-
} else {
30-
return '';
31-
}
32-
} else {
33-
// We match a string
34-
return match;
35-
}
36-
});
37-
return result;
38-
}
39-
4010

4111
describe('test code generator', function () {
4212
this.timeout(10000);
@@ -753,7 +723,7 @@ describe('test code generator', function () {
753723

754724
runResult.assertJsonFileContent('testCom/package.json', expectedPackageJSON);
755725

756-
const tsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/tsconfig.json')));
726+
const tsconfigBody = parse(runResult.fs.read('testCom/tsconfig.json'));
757727
runResult.assertObjectContent(tsconfigBody, expectedTsConfig);
758728
} finally {
759729
cleanup(runResult);
@@ -833,7 +803,7 @@ describe('test code generator', function () {
833803

834804
runResult.assertJsonFileContent('testCom/package.json', expectedPackageJSON);
835805

836-
const tsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/tsconfig.json')));
806+
const tsconfigBody = parse(runResult.fs.read('testCom/tsconfig.json'));
837807
runResult.assertObjectContent(tsconfigBody, expectedTsConfig);
838808
} finally {
839809
cleanup(runResult);
@@ -1196,7 +1166,7 @@ describe('test code generator', function () {
11961166
]
11971167
};
11981168

1199-
const jsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/jsconfig.json')));
1169+
const jsconfigBody = parse(runResult.fs.read('testCom/jsconfig.json'));
12001170
runResult.assertObjectContent(jsconfigBody, expectedJSConfig);
12011171
} finally {
12021172
cleanup(runResult);

0 commit comments

Comments
 (0)