Skip to content

Commit

Permalink
build: remove tsetse rule exclusions
Browse files Browse the repository at this point in the history
To remove the tsetse rule exclusions, several usages of `JSON.parse` that
did not have type casting where adjusted to add types. This removed the
need for the manual configuration within the tsconfig.
  • Loading branch information
clydin committed Jun 24, 2024
1 parent 3e359da commit 579f817
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/config/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function normalizeValue(value: string | undefined | boolean | number): JsonValue
// and convert them into a numberic entities.
// Example: 73b61974-182c-48e4-b4c6-30ddf08c5c98 -> 73.
// These values should never contain comments, therefore using `JSON.parse` is safe.
return JSON.parse(valueString);
return JSON.parse(valueString) as JsonValue;
} catch {
return value;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/update/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
if (existsSync(packageJsonPath)) {
const content = await fs.readFile(packageJsonPath, 'utf-8');
if (content) {
const { bin = {} } = JSON.parse(content);
const { bin = {} } = JSON.parse(content) as { bin: Record<string, string> };
const binKeys = Object.keys(bin);

if (binKeys.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/utilities/package-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface PackageTreeNode {

export async function readPackageJson(packageJsonPath: string): Promise<PackageJson | undefined> {
try {
return JSON.parse((await fs.promises.readFile(packageJsonPath)).toString());
return JSON.parse((await fs.promises.readFile(packageJsonPath)).toString()) as PackageJson;
} catch {
return undefined;
}
Expand Down
12 changes: 7 additions & 5 deletions packages/angular/cli/src/utilities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import * as os from 'os';
import * as path from 'path';
import { findUp } from './find-up';

interface PackageDependencies {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
}

export function findWorkspaceFile(currentDirectory = process.cwd()): string | null {
const possibleConfigFiles = ['angular.json', '.angular.json'];
const configFilePath = findUp(possibleConfigFiles, currentDirectory);
Expand All @@ -27,7 +32,7 @@ export function findWorkspaceFile(currentDirectory = process.cwd()): string | nu

try {
const packageJsonText = fs.readFileSync(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonText);
const packageJson = JSON.parse(packageJsonText) as PackageDependencies;
if (!containsCliDep(packageJson)) {
// No CLI dependency
return null;
Expand All @@ -41,10 +46,7 @@ export function findWorkspaceFile(currentDirectory = process.cwd()): string | nu
return configFilePath;
}

function containsCliDep(obj?: {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
}): boolean {
function containsCliDep(obj?: PackageDependencies): boolean {
const pkgName = '@angular/cli';
if (!obj) {
return false;
Expand Down
9 changes: 1 addition & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
"@angular/build/private": ["./packages/angular/build/src/private"],
"@ngtools/webpack": ["./packages/ngtools/webpack/src"],
"@schematics/angular": ["./packages/schematics/angular"]
},
"plugins": [
{
"name": "@bazel/tsetse",
// must-use-promises is handled by the eslint @typescript-eslint/no-floating-promises rule
"disabledRules": ["must-type-assert-json-parse", "must-use-promises"]
}
]
}
},
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
Expand Down

0 comments on commit 579f817

Please sign in to comment.