typescript-strictly-typed
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -16,8 +16,5 @@ "use strict"; | ||
function enableESLintStrict(cwd) { | ||
var _a; | ||
var _a, _b; | ||
const possibleConfigFiles = ['.eslintrc.json', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.js', 'package.json']; | ||
const eslintTypeScriptPlugin = '@typescript-eslint'; | ||
const eslintVuePlugin = '@vue/typescript'; | ||
const eslintReactPlugin = 'react-app'; | ||
const eslintTypeScriptParser = '@typescript-eslint/parser'; | ||
const filesConfig = '*.ts'; | ||
let config = null; | ||
@@ -42,16 +39,18 @@ let packageJSONConfig = null; | ||
} | ||
if (!((config.parser === eslintTypeScriptParser && Array.isArray(config.plugins) && config.plugins.includes(eslintTypeScriptPlugin)) || | ||
(config.extends === eslintReactPlugin) || | ||
(Array.isArray(config.extends) && config.extends.includes(eslintVuePlugin)))) { | ||
log_utils_1.logWarning(`${file} must be configured with "parser": "${eslintTypeScriptParser}" and "plugins": ["${eslintTypeScriptPlugin}"] (or an equivalent like "extends": ["${eslintVuePlugin}"] or "extends": "${eslintReactPlugin}"), otherwise rules won't be checked.`); | ||
checkConfig(config); | ||
let configAdded = false; | ||
/* If there is an override, rules must be set inside it, or they won't be checked */ | ||
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); | ||
configAdded = true; | ||
} | ||
} | ||
if (!config.rules) { | ||
config.rules = {}; | ||
/* Add rules at root level if there was no override */ | ||
if (!configAdded) { | ||
addConfig(config); | ||
} | ||
if (!config.rules['@typescript-eslint/no-explicit-any']) { | ||
config.rules['@typescript-eslint/no-explicit-any'] = 'error'; | ||
} | ||
if (!config.rules['@typescript-eslint/explicit-function-return-type']) { | ||
config.rules['@typescript-eslint/explicit-function-return-type'] = 'error'; | ||
} | ||
if (packageJSONConfig) { | ||
@@ -70,1 +69,45 @@ packageJSONConfig.eslintConfig = config; | ||
exports.default = enableESLintStrict; | ||
function checkConfig(config) { | ||
var _a, _b; | ||
const eslintTypeScriptPlugin = '@typescript-eslint'; | ||
const eslintReactPlugin = 'react-app'; | ||
const eslintVuePlugin = '@vue/typescript'; | ||
const eslintAngularPlugin = '@angular-eslint'; | ||
const eslintExtensionPlugins = [eslintReactPlugin, eslintVuePlugin, eslintAngularPlugin]; | ||
/* Case: @typescript-eslint */ | ||
if ((_a = config.plugins) === null || _a === void 0 ? void 0 : _a.includes(eslintTypeScriptPlugin)) | ||
return; | ||
/* Case: extensions */ | ||
for (const extension of eslintExtensionPlugins) { | ||
/* Case: plugin in `extends` */ | ||
const configExtends = Array.isArray(config.extends) ? config.extends : | ||
config.extends ? [config.extends] : | ||
[]; | ||
for (const configExtend of configExtends) { | ||
if (configExtend.includes(extension)) | ||
return; | ||
} | ||
/* Case: plugin in `overrides[x].extends` */ | ||
for (const override of (_b = config.overrides) !== null && _b !== void 0 ? _b : []) { | ||
const overrideExtends = Array.isArray(override.extends) ? override.extends : | ||
override.extends ? [override.extends] : | ||
[]; | ||
for (const overrideExtend of overrideExtends) { | ||
if (overrideExtend.includes(extension)) | ||
return; | ||
} | ||
} | ||
} | ||
log_utils_1.logWarning(`ESLint must be configured with "${eslintTypeScriptPlugin}" plugin or with a tool extending it like "${eslintVuePlugin}", "${eslintReactPlugin}" or "${eslintAngularPlugin}", otherwise rules won't be checked.`); | ||
} | ||
function addConfig(config) { | ||
if (!config.rules) { | ||
config.rules = {}; | ||
} | ||
if (!config.rules['@typescript-eslint/no-explicit-any']) { | ||
config.rules['@typescript-eslint/no-explicit-any'] = 'error'; | ||
} | ||
if (!config.rules['@typescript-eslint/explicit-function-return-type']) { | ||
config.rules['@typescript-eslint/explicit-function-return-type'] = 'error'; | ||
} | ||
} |
@@ -23,6 +23,5 @@ "use strict"; | ||
if (eslint_strict_1.default(cwd)) { | ||
log_utils_1.logInfo(`Skipping TSLint configuration as ESLint has been found and configured.`); | ||
success.push('ESLint'); | ||
} | ||
else if (tslint_strict_1.default(cwd)) { | ||
if (tslint_strict_1.default(cwd)) { | ||
success.push('TSLint'); | ||
@@ -29,0 +28,0 @@ } |
{ | ||
"name": "typescript-strictly-typed", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Enable configurations for strictly typed TypeScript, ESLint or TSLint, and optionally Angular.", | ||
@@ -55,7 +55,7 @@ "funding": { | ||
"@types/json5": "0.0.30", | ||
"@types/node": "14.14.6", | ||
"@typescript-eslint/eslint-plugin": "4.6.1", | ||
"@typescript-eslint/parser": "4.6.1", | ||
"@types/node": "14.14.7", | ||
"@typescript-eslint/eslint-plugin": "4.7.0", | ||
"@typescript-eslint/parser": "4.7.0", | ||
"copyfiles": "2.4.0", | ||
"eslint": "7.12.1", | ||
"eslint": "7.13.0", | ||
"rimraf": "3.0.2", | ||
@@ -62,0 +62,0 @@ "typescript": "4.0.5" |
@@ -51,3 +51,3 @@ # TypeScript Strictly Typed | ||
- `strictInputAccessModifiers` | ||
- [Angular Codelyzer lint options](http://codelyzer.com) | ||
- [Angular Codelyzer lint options](http://codelyzer.com/rules/) | ||
- `template-no-any` | ||
@@ -105,15 +105,2 @@ | ||
### React apps | ||
For React apps created with `create-react-app`, after running this lib command, | ||
it will work out of the box: | ||
- in your editor (for example if you have the ESLint extension in Visual Studio Code) | ||
- if you run lint manually (for example with `eslint src/**` command) | ||
But it won't be taken into account at React compilation (ie. on `npm start`), | ||
because React does custom things. | ||
See [issue #2](https://github.com/cyrilletuzi/typescript-strictly-typed/issues/2) | ||
if you want to help. | ||
### Apps using `.eslintrc.js` (including Vue) | ||
@@ -120,0 +107,0 @@ |
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
23413
436
128