Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix-page-links-size
Browse files Browse the repository at this point in the history
* origin/main:
  fix(components/packages): accommodate vscode settings with json comments (#2833)
  • Loading branch information
johnhwhite committed Oct 16, 2024
2 parents e5d31ab + be34b8d commit d1309bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ describe('vscode-eslint-setting.schematic', () => {
});
});

it(`should run successfully with comments`, async () => {
const { runner, tree } = setupTest(
'.eslintrc.js',
`
// Comment.
{}
`,
);

await runner.runSchematic('vscode-eslint-setting', undefined, tree);
expect(tree.readJson('.vscode/settings.json')).toEqual({
'eslint.useFlatConfig': false,
});
});

const possibleFlatConfigFiles = [
'eslint.config.js',
'eslint.config.mjs',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Rule, Tree } from '@angular-devkit/schematics';

import { parse } from 'jsonc-parser';

import { readRequiredFile, writeJsonFile } from '../../../utility/tree';

const packageJsonPath = '/package.json';
Expand All @@ -9,7 +11,7 @@ function getVSCodeSettings(tree: Tree): {
'eslint.useFlatConfig'?: boolean;
} {
if (tree.exists(vscodeSettingsPath)) {
return JSON.parse(readRequiredFile(tree, vscodeSettingsPath));
return parse(readRequiredFile(tree, vscodeSettingsPath), [], {});
} else {
return {};
}
Expand Down

0 comments on commit d1309bd

Please sign in to comment.