typescript-strictly-typed
Advanced tools
Comparing version 2.4.0 to 2.5.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.saveConfig = exports.getConfig = exports.findConfig = void 0; | ||
exports.checkDependencyVersion = exports.saveConfig = exports.getConfig = exports.findConfig = void 0; | ||
const path = require("path"); | ||
@@ -8,2 +8,4 @@ const fs = require("fs"); | ||
const yaml = require("js-yaml"); | ||
const pkg_up_1 = require("pkg-up"); | ||
const semver = require("semver"); | ||
const log_utils_1 = require("./log-utils"); | ||
@@ -106,1 +108,24 @@ /** | ||
exports.saveConfig = saveConfig; | ||
/** | ||
* Check a dependency version | ||
* | ||
* @param cwd Working directory path | ||
* @param name Dependency name to check | ||
* @param wantedVersion Wanted version, eg. `>=2.1.0` | ||
*/ | ||
function checkDependencyVersion(cwd, name, wantedVersion) { | ||
var _a, _b; | ||
const filePath = pkg_up_1.sync({ cwd }); | ||
if (filePath) { | ||
const packageJsonFile = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
const packageJsonConfig = json5.parse(packageJsonFile); | ||
const prodDependencyVersion = (_a = packageJsonConfig === null || packageJsonConfig === void 0 ? void 0 : packageJsonConfig.dependencies) === null || _a === void 0 ? void 0 : _a[name]; | ||
const devDependencyVersion = (_b = packageJsonConfig === null || packageJsonConfig === void 0 ? void 0 : packageJsonConfig.devDependencies) === null || _b === void 0 ? void 0 : _b[name]; | ||
const dependencyVersion = semver.coerce(prodDependencyVersion !== null && prodDependencyVersion !== void 0 ? prodDependencyVersion : devDependencyVersion); | ||
if (dependencyVersion) { | ||
return semver.satisfies(dependencyVersion, wantedVersion); | ||
} | ||
} | ||
return false; | ||
} | ||
exports.checkDependencyVersion = checkDependencyVersion; |
@@ -16,5 +16,7 @@ "use strict"; | ||
function enableESLintStrict(cwd) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const possibleConfigFiles = ['.eslintrc.json', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.js', 'package.json']; | ||
const filesConfig = '*.ts'; | ||
const tsFilesConfig = '*.ts'; | ||
const htmlFilesConfig = '*.html'; | ||
const eslintAngularTemplatePlugin = '@angular-eslint/template'; | ||
let config = null; | ||
@@ -42,11 +44,14 @@ let packageJSONConfig = null; | ||
for (const override of (_b = config.overrides) !== null && _b !== void 0 ? _b : []) { | ||
const files = Array.isArray(override.files) ? override.files : | ||
override.files ? [override.files] : | ||
[]; | ||
if (files.some((file) => file.includes(filesConfig))) { | ||
addConfig(override); | ||
const files = normalizeConfigToArray(override.files); | ||
if (files.some((file) => file.includes(tsFilesConfig))) { | ||
addTSConfig(override); | ||
} | ||
if (files.some((file) => file.includes(htmlFilesConfig))) { | ||
const extendsConfig = normalizeConfigToArray(override.extends); | ||
if (((_c = override.plugins) === null || _c === void 0 ? void 0 : _c.includes(eslintAngularTemplatePlugin)) || extendsConfig.some((extendConfig) => extendConfig.includes(eslintAngularTemplatePlugin))) | ||
addAngularHTMLConfig(override); | ||
} | ||
} | ||
/* Add rules at root level */ | ||
addConfig(config); | ||
addTSConfig(config); | ||
if (packageJSONConfig) { | ||
@@ -66,3 +71,3 @@ packageJSONConfig.eslintConfig = config; | ||
function checkConfig(config) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const eslintTypeScriptPlugin = '@typescript-eslint'; | ||
@@ -79,5 +84,3 @@ const eslintReactPlugin = 'react-app'; | ||
/* Case: plugin in `extends` */ | ||
const configExtends = Array.isArray(config.extends) ? config.extends : | ||
config.extends ? [config.extends] : | ||
[]; | ||
const configExtends = normalizeConfigToArray(config.extends); | ||
for (const configExtend of configExtends) { | ||
@@ -89,5 +92,5 @@ if (configExtend.includes(extension)) | ||
for (const override of (_b = config.overrides) !== null && _b !== void 0 ? _b : []) { | ||
const overrideExtends = Array.isArray(override.extends) ? override.extends : | ||
override.extends ? [override.extends] : | ||
[]; | ||
if ((_c = override.plugins) === null || _c === void 0 ? void 0 : _c.includes(eslintTypeScriptPlugin)) | ||
return; | ||
const overrideExtends = normalizeConfigToArray(override.extends); | ||
for (const overrideExtend of overrideExtends) { | ||
@@ -101,3 +104,3 @@ if (overrideExtend.includes(extension)) | ||
} | ||
function addConfig(config) { | ||
function addTSConfig(config) { | ||
if (!config.rules) { | ||
@@ -109,1 +112,10 @@ config.rules = {}; | ||
} | ||
function addAngularHTMLConfig(config) { | ||
if (!config.rules) { | ||
config.rules = {}; | ||
} | ||
config.rules['@angular-eslint/template/no-any'] = 'error'; | ||
} | ||
function normalizeConfigToArray(config) { | ||
return Array.isArray(config) ? config : config ? [config] : []; | ||
} |
{ | ||
"name": "typescript-strictly-typed", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Enable configurations for strictly typed TypeScript, ESLint or TSLint, and optionally Angular.", | ||
@@ -49,4 +49,6 @@ "funding": { | ||
"chalk": "4.1.0", | ||
"js-yaml": "3.14.0", | ||
"json5": "2.1.3" | ||
"js-yaml": "3.14.1", | ||
"json5": "2.1.3", | ||
"pkg-up": "3.1.0", | ||
"semver": "7.3.4" | ||
}, | ||
@@ -56,10 +58,11 @@ "devDependencies": { | ||
"@types/json5": "0.0.30", | ||
"@types/node": "14.14.9", | ||
"@typescript-eslint/eslint-plugin": "4.8.1", | ||
"@typescript-eslint/parser": "4.8.1", | ||
"copyfiles": "2.4.0", | ||
"eslint": "7.13.0", | ||
"@types/node": "14.14.17", | ||
"@types/semver": "7.3.4", | ||
"@typescript-eslint/eslint-plugin": "4.11.1", | ||
"@typescript-eslint/parser": "4.11.1", | ||
"copyfiles": "2.4.1", | ||
"eslint": "7.16.0", | ||
"rimraf": "3.0.2", | ||
"typescript": "4.1.2" | ||
"typescript": "4.1.3" | ||
} | ||
} |
@@ -41,2 +41,6 @@ # TypeScript Strictly Typed | ||
- `strict` (which includes in particular `noImplicitAny` and `strictNullChecks`) | ||
- `noFallthroughCasesInSwitch` | ||
- `noImplicitReturns` | ||
- `noUncheckedIndexedAccess` | ||
- `forceConsistentCasingInFileNames` | ||
- [ESLint rules](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) | ||
@@ -52,2 +56,4 @@ - `@typescript-eslint/no-explicit-any` | ||
- `strictInputAccessModifiers` | ||
- [Angular ESLint options](https://github.com/angular-eslint/angular-eslint) | ||
- `@angular-eslint/template/no-any` | ||
- [Angular Codelyzer lint options](http://codelyzer.com/rules/) | ||
@@ -54,0 +60,0 @@ - `template-no-any` |
@@ -7,2 +7,6 @@ "use strict"; | ||
* - `strict` | ||
* - `noFallthroughCasesInSwitch` | ||
* - `noImplicitReturns` | ||
* - `noUncheckedIndexedAccess` | ||
* - `forceConsistentCasingInFileNames` | ||
* {@link https://www.typescriptlang.org/docs/handbook/compiler-options.html} | ||
@@ -27,2 +31,8 @@ * | ||
config.compilerOptions.strict = true; | ||
config.compilerOptions.noFallthroughCasesInSwitch = true; | ||
config.compilerOptions.noImplicitReturns = true; | ||
config.compilerOptions.forceConsistentCasingInFileNames = true; | ||
if (config_utils_1.checkDependencyVersion(cwd, 'typescript', '>=4.1.0')) { | ||
config.compilerOptions.noUncheckedIndexedAccess = true; | ||
} | ||
/* Clean up options included in strict mode */ | ||
@@ -29,0 +39,0 @@ if (config.compilerOptions.alwaysStrict) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25969
477
134
5
10
+ Addedpkg-up@3.1.0
+ Addedsemver@7.3.4
+ Addedfind-up@3.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedlocate-path@3.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@3.0.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpkg-up@3.1.0(transitive)
+ Addedsemver@7.3.4(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedjs-yaml@3.14.0(transitive)
Updatedjs-yaml@3.14.1