typescript-strictly-typed
Advanced tools
Comparing version 3.19.3 to 3.20.0
@@ -53,2 +53,3 @@ import { dump, load } from "js-yaml"; | ||
raw, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
json: parse(raw), | ||
@@ -60,2 +61,3 @@ }; | ||
case ".yml": { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
const json = load(raw); | ||
@@ -70,2 +72,3 @@ config = { | ||
case ".cjs": { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
const moduleImport = await import(filePath); | ||
@@ -149,2 +152,3 @@ const json = moduleImport.default; | ||
const packageJsonFile = readFileSync(filePath, { encoding: "utf8" }); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
const packageJsonConfig = parse(packageJsonFile); | ||
@@ -170,2 +174,3 @@ const prodDependencyVersion = packageJsonConfig?.dependencies?.[name]; | ||
const packageJsonFile = readFileSync(filePath, { encoding: "utf8" }); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
const packageJsonConfig = parse(packageJsonFile); | ||
@@ -172,0 +177,0 @@ if (packageJsonConfig?.dependencies && (name in packageJsonConfig.dependencies)) { |
@@ -6,31 +6,34 @@ import { writeFileSync } from "node:fs"; | ||
import { logWarning } from "./log-utils.js"; | ||
const eslintRules = { | ||
"eqeqeq": `"error"`, | ||
"prefer-arrow-callback": `"error"`, | ||
"prefer-template": `"error"`, | ||
"@typescript-eslint/explicit-function-return-type": `"error"`, | ||
"@typescript-eslint/no-explicit-any": `"error"`, | ||
"@typescript-eslint/no-non-null-assertion": `"error"`, | ||
"@typescript-eslint/no-unsafe-argument": `"error"`, | ||
"@typescript-eslint/no-unsafe-assignment": `"error"`, | ||
"@typescript-eslint/no-unsafe-call": `"error"`, | ||
"@typescript-eslint/no-unsafe-member-access": `"error"`, | ||
"@typescript-eslint/no-unsafe-return": `"error"`, | ||
"@typescript-eslint/prefer-for-of": `"error"`, | ||
"@typescript-eslint/prefer-nullish-coalescing": `"error"`, | ||
"@typescript-eslint/prefer-optional-chain": `"error"`, | ||
"@typescript-eslint/restrict-plus-operands": `["error", { | ||
allowAny: false, | ||
allowBoolean: false, | ||
allowNullish: false, | ||
allowNumberAndString: false, | ||
allowRegExp: false, | ||
}]`, | ||
"@typescript-eslint/restrict-template-expressions": `"error"`, | ||
"@typescript-eslint/strict-boolean-expressions": `["error", { | ||
allowNumber: false, | ||
allowString: false, | ||
}]`, | ||
"@typescript-eslint/use-unknown-in-catch-callback-variable": `"error"`, | ||
}; | ||
function getEslintRules(cwd) { | ||
return { | ||
"eqeqeq": `"error"`, | ||
"prefer-arrow-callback": `"error"`, | ||
"prefer-template": `"error"`, | ||
"@typescript-eslint/explicit-function-return-type": `"error"`, | ||
"@typescript-eslint/no-explicit-any": `"error"`, | ||
"@typescript-eslint/no-non-null-assertion": `"error"`, | ||
"@typescript-eslint/no-unsafe-argument": `"error"`, | ||
"@typescript-eslint/no-unsafe-assignment": `"error"`, | ||
"@typescript-eslint/no-unsafe-call": `"error"`, | ||
"@typescript-eslint/no-unsafe-member-access": `"error"`, | ||
"@typescript-eslint/no-unsafe-return": `"error"`, | ||
...(checkDependencyVersion(cwd, "@typescript-eslint/eslint-plugin", ">=8.15.0") ? { "@typescript-eslint/no-unsafe-type-assertion": `"error"` } : {}), | ||
"@typescript-eslint/prefer-for-of": `"error"`, | ||
"@typescript-eslint/prefer-nullish-coalescing": `"error"`, | ||
"@typescript-eslint/prefer-optional-chain": `"error"`, | ||
"@typescript-eslint/restrict-plus-operands": `["error", { | ||
allowAny: false, | ||
allowBoolean: false, | ||
allowNullish: false, | ||
allowNumberAndString: false, | ||
allowRegExp: false, | ||
}]`, | ||
"@typescript-eslint/restrict-template-expressions": `"error"`, | ||
"@typescript-eslint/strict-boolean-expressions": `["error", { | ||
allowNumber: false, | ||
allowString: false, | ||
}]`, | ||
"@typescript-eslint/use-unknown-in-catch-callback-variable": `"error"`, | ||
}; | ||
} | ||
export function enableESLintFlatStrict(cwd) { | ||
@@ -139,3 +142,3 @@ const fileName = findConfig(cwd, ["eslint.config.mjs", "eslint.config.js"]); | ||
} | ||
for (const [ruleName, ruleErrorConfig] of Object.entries(eslintRules)) { | ||
for (const [ruleName, ruleErrorConfig] of Object.entries(getEslintRules(cwd))) { | ||
const ruleProperty = getProperty(rulesObject, ruleName); | ||
@@ -142,0 +145,0 @@ if (ruleProperty) { |
@@ -1,2 +0,2 @@ | ||
import { dependencyExists, findConfig, getConfig, getSource, isAngularESLint, modifyJSON, saveConfig } from "./config-utils.js"; | ||
import { checkDependencyVersion, dependencyExists, findConfig, getConfig, getSource, isAngularESLint, modifyJSON, saveConfig } from "./config-utils.js"; | ||
import { enableESLintFlatStrict } from "./eslint-flat-strict.js"; | ||
@@ -58,3 +58,3 @@ import { logInfo, logWarning } from "./log-utils.js"; | ||
} | ||
addTSConfig(config, ["overrides", indexNumber], config.json.overrides?.[indexNumber]?.rules); | ||
addTSConfig(cwd, config, ["overrides", indexNumber], config.json.overrides?.[indexNumber]?.rules); | ||
tsConfigAdded = true; | ||
@@ -71,3 +71,3 @@ } | ||
} | ||
addTSConfig(config, [], config.json.rules); | ||
addTSConfig(cwd, config, [], config.json.rules); | ||
} | ||
@@ -95,3 +95,3 @@ if (!dependencyExists(cwd, "@typescript-eslint/eslint-plugin") && !dependencyExists(cwd, "typescript-eslint")) { | ||
} | ||
function addTSConfig(config, path, rules) { | ||
function addTSConfig(cwd, config, path, rules) { | ||
config.raw = modifyJSON(config.raw, [...path, "rules", "eqeqeq"], "error"); | ||
@@ -116,2 +116,5 @@ config.raw = modifyJSON(config.raw, [...path, "rules", "prefer-arrow-callback"], "error"); | ||
config.raw = modifyJSON(config.raw, [...path, "rules", "@typescript-eslint/no-unsafe-return"], "error"); | ||
if (checkDependencyVersion(cwd, "@typescript-eslint/eslint-plugin", ">=8.15.0")) { | ||
config.raw = modifyJSON(config.raw, [...path, "rules", "@typescript-eslint/no-unsafe-type-assertion"], "error"); | ||
} | ||
config.raw = modifyJSON(config.raw, [...path, "rules", "@typescript-eslint/prefer-for-of"], "error"); | ||
@@ -118,0 +121,0 @@ config.raw = modifyJSON(config.raw, [...path, "rules", "@typescript-eslint/prefer-nullish-coalescing"], "error"); |
{ | ||
"name": "typescript-strictly-typed", | ||
"version": "3.19.3", | ||
"version": "3.20.0", | ||
"description": "Enable configurations for strictly typed TypeScript, ESLint, and optionally Angular.", | ||
@@ -40,19 +40,19 @@ "funding": { | ||
"js-yaml": "^4.1.0", | ||
"jsonc-parser": "^3.2.1", | ||
"jsonc-parser": "^3.3.1", | ||
"package-up": "^5.0.0", | ||
"semver": "^7.6.2", | ||
"ts-morph": "^22.0.0" | ||
"semver": "^7.6.3", | ||
"ts-morph": "^24.0.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.8.2", | ||
"@biomejs/biome": "^1.9.4", | ||
"@types/js-yaml": "^4.0.9", | ||
"@types/node": "^18.19.38", | ||
"@types/node": "~22.9.0", | ||
"@types/semver": "^7.5.8", | ||
"better-typescript-lib": "^2.7.0", | ||
"better-typescript-lib": "^2.9.0", | ||
"copyfiles": "^2.4.1", | ||
"eslint": "^9.5.0", | ||
"rimraf": "^5.0.7", | ||
"typescript": "~5.4.5", | ||
"typescript-eslint": "^8.0.0-alpha.24" | ||
"eslint": "^9.15.0", | ||
"rimraf": "^6.0.1", | ||
"typescript": "~5.6.2", | ||
"typescript-eslint": "^8.15.0" | ||
} | ||
} |
41510
863
+ Added@ts-morph/common@0.25.0(transitive)
+ Addedfdir@6.4.3(transitive)
+ Addedpicomatch@4.0.2(transitive)
+ Addedtinyglobby@0.2.12(transitive)
+ Addedts-morph@24.0.0(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@ts-morph/common@0.23.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedfast-glob@3.3.3(transitive)
- Removedfastq@1.19.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedmkdirp@3.0.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.1.0(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedts-morph@22.0.0(transitive)
Updatedjsonc-parser@^3.3.1
Updatedsemver@^7.6.3
Updatedts-morph@^24.0.0