Extended tslint.json from tslint:all (#612)

* Extended tslint.json from tslint:all

Changes `getRuleNames` utility to `getContribuRuleNames` and no longer retrieve core TSLint rules. Also adds comments and sections in our `tslint.json` to help distinguish classes of rule settings.

* Fixed validate-config for all disabled rule values

* Explicitly listed our disabled rules
This commit is contained in:
Josh Goldberg 2018-10-30 12:05:06 -04:00 коммит произвёл GitHub
Родитель 66ea76a8f9
Коммит 373918c791
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 212 добавлений и 310 удалений

Просмотреть файл

@ -1,5 +1,6 @@
const fs = require('fs');
const { red } = require('chalk');
const fs = require('fs');
const stripJsonComments = require("strip-json-comments");
function readFile(fileName) {
try {
@ -28,8 +29,18 @@ function readJSON(fileName) {
}
}
function readJSONWithComments(fileName) {
try {
return JSON.parse(stripJsonComments(readFile(fileName)));
} catch (e) {
console.log(red(`Unable to parse commented JSON file: ${ fileName }. \n ${ e }`));
process.exit(1);
}
}
module.exports = {
readFile,
readJSON,
readJSONWithComments,
writeFile
};

Просмотреть файл

@ -65,7 +65,7 @@ function kebabCase(input) {
}, '');
}
function getAllRuleNames(options = { skipTsLintRules: false }) {
function getContribRuleNames() {
const convertToRuleNames = filename => {
filename = filename
.replace(/Rule\..*/, '') // file extension plus Rule suffix
@ -74,17 +74,9 @@ function getAllRuleNames(options = { skipTsLintRules: false }) {
return kebabCase(filename);
};
const contribRules = glob.sync('src/*Rule.ts').map(convertToRuleNames);
let baseRules = [];
if (!options.skipTsLintRules) {
baseRules = glob.sync('node_modules/tslint/lib/rules/*Rule.js').map(convertToRuleNames);
}
const allRules = baseRules.concat(contribRules);
allRules.sort();
return allRules;
return glob.sync('src/*Rule.ts')
.map(convertToRuleNames)
.sort();
}
function getAllFormatterNames() {
@ -104,7 +96,7 @@ function getAllFormatterNames() {
module.exports = {
getAllFormatterNames,
getAllRuleNames,
getContribRuleNames,
getAllRules,
getMetadataFromFile,
getMetadataValue

Просмотреть файл

@ -2,62 +2,51 @@
* Makes sure all the rules in the project are defined to run during the build.
*/
const { yellowBright } = require('chalk');
const { readJSON } = require('./common/files');
const { getAllRuleNames } = require('./common/meta');
const { yellow, yellowBright } = require('chalk');
const { readJSONWithComments } = require('./common/files');
const { getContribRuleNames } = require('./common/meta');
const tslintConfig = readJSON('tslint.json');
const tslintConfig = readJSONWithComments('tslint.json');
const rulesToSkip = new Set([
'align', // no need
'ban-types',
'comment-format', // no need
'completed-docs', // no need
'cyclomatic-complexity', // too strict
'deprecation', // requires type checking
'file-header', // no need
'file-name-casing', // too strict
'interface-name', // no need
'match-default-export-name', // requires type checking
'max-classes-per-file', // no need
'max-file-line-count', // no need
'member-ordering', // too strict
'newline-before-return', // kind of a silly rule
'newline-per-chained-call', // too strict
'no-dynamic-delete', // too strict
'no-empty-line-after-opening-brace', // too strict
'no-inferrable-types', // we prefer the opposite
'no-multiline-string', // too strict
'no-non-null-assertion', // in fact we prefer the opposite rule
'no-parameter-reassignment', // turn this on eventually
'no-relative-imports', // this project uses relative imports
'no-unexternalized-strings', // this is a VS Code specific rule
'no-unnecessary-type-assertion', // requires type checking
'no-unused-variable', // requires type checking
'ordered-imports', // too difficult to turn on
'prefer-conditional-expression', // not sure if this is needed
'prefer-switch', // no need
'prefer-template', // rule does not handle multi-line strings nicely
'prefer-while', // not sure if this is needed
'return-undefined', // requires type checking
'type-literal-delimiter', // not sure if this is needed
'typedef-whitespace', // too strict
'use-default-type-parameter' // requires type checking
function ruleIsEnabled(value) {
if (value === undefined) {
return false;
}
if (typeof value === "boolean") {
return value;
}
return value[0];
}
const disabledRules = new Set([
"missing-jsdoc",
"no-duplicate-case",
"no-empty-interfaces",
"no-empty-line-after-opening-brace",
"no-multiline-string",
"no-relative-imports",
"no-stateless-class",
"no-unexternalized-strings",
"no-var-self",
"react-tsx-curly-spacing",
"valid-typeof",
]);
const errors = [];
getAllRuleNames().forEach(ruleName => {
if (rulesToSkip.has(ruleName)) {
getContribRuleNames().forEach(ruleName => {
if (disabledRules.has(ruleName)) {
return;
}
if (tslintConfig.rules[ruleName] !== true && tslintConfig.rules[ruleName] !== false) {
if (tslintConfig.rules[ruleName] === undefined || tslintConfig.rules[ruleName][0] !== true) {
errors.push('A rule was found that is not enabled on the project: ' + ruleName);
}
if (!ruleIsEnabled(tslintConfig.rules[ruleName])) {
errors.push('A tslint-microsoft-contrib rule was found that is not enabled on the project: ' + ruleName);
}
});
if (errors.length > 0) {
console.log(yellowBright(errors.join('\n')));
console.log(yellow(errors.join('\n')));
console.log(yellowBright(`Add the missing rule${errors.length === 1 ? '' : 's'} to tslint.json.`));
process.exit(1);
}

Просмотреть файл

@ -5,13 +5,13 @@
const { yellowBright } = require('chalk');
const { readFile, readJSON } = require('./common/files');
const { getAllFormatterNames, getAllRuleNames } = require('./common/meta');
const { getAllFormatterNames, getContribRuleNames } = require('./common/meta');
const readmeText = readFile('README.md');
const packageJson = readJSON('package.json');
const validationErrors = [];
getAllRuleNames({ skipTsLintRules: true }).forEach(ruleName => {
getContribRuleNames().forEach(ruleName => {
if (readmeText.indexOf(ruleName) === -1) {
validationErrors.push('A rule was found that is not documented in README.md: ' + ruleName);
}

6
package-lock.json сгенерированный
Просмотреть файл

@ -2296,6 +2296,12 @@
"ansi-regex": "^2.0.0"
}
},
"strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
"dev": true
},
"supports-color": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",

Просмотреть файл

@ -47,8 +47,8 @@
"generate:sdl-report": "node build-tasks/generate-sdl-report.js",
"generate:rule-metadata": "node build-tasks/generate-rule-metadata.js",
"generate:package-json-for-npm": "node build-tasks/generate-package-json-for-npm.js",
"lint:rules": "tslint -p tsconfig.json -r dist/src -t verbose -c tslint.json -e \"src/tests/**\" \"src/**/*.ts\"",
"lint:tests": "tslint -p tsconfig.json -r dist/src -t verbose -c src/tests/tslint.json -e src/tests/references.ts \"src/tests/**/*.ts\"",
"lint:rules": "tslint -p tsconfig.json -t stylish -c tslint.json -e \"src/tests/**\" \"src/**/*.ts\"",
"lint:tests": "tslint -p tsconfig.json -t stylish -c src/tests/tslint.json -e src/tests/references.ts \"src/tests/**/*.ts\"",
"start": "tsc --watch",
"test:mocha": "mocha \"dist/src/tests/**/*.js\" --timeout 5000",
"test:rules": "tslint -r dist/src --test \"tests/**\"",
@ -71,6 +71,7 @@
"mocha": "5.2.0",
"npm-run-all": "^4.1.3",
"rimraf": "^2.6.2",
"strip-json-comments": "^2.0.1",
"tslint": "^5.11.0",
"typescript": "3.1.1",
"underscore": "1.9.1"

Просмотреть файл

@ -286,7 +286,7 @@ return-undefined,Prefer `return;` in void functions and `return undefined;` in v
semicolon,Enforces consistent semicolon usage at the end of every statement.,TSLINT1L591RI,tslint,Non-SDL,Warning,Moderate,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,"398, 710","CWE 398 - Indicator of Poor Code Quality
CWE 710 - Coding Standards Violation"
space-within-parens,Enforces spaces within parentheses or disallow them. Empty parentheses () are always allowed.,TSLINT1E89MLR,tslint,Non-SDL,Warning,Low,Opportunity for Excellence,See description on the tslint or tslint-microsoft-contrib website,TSLint Procedure,710,"CWE 710 - Coding Standards Violation"
strict-boolean-expressions,"Restricts the types allowed in boolean expressions. By default only booleans are allowed.
strict-boolean-expressions,"Restricts the types allowed in boolean expressions. By default only booleans are allowed.
The following nodes are checked:
* Arguments to the `!`, `&&`, and `||` operators

Не удается отобразить этот файл, потому что он содержит неожиданный символ в строке 147 и столбце 45.

Просмотреть файл

@ -1,94 +1,15 @@
{
"extends": "tslint:all",
"rulesDirectory": [
"dist/src"
],
"rules": {
// Core rules with custom configurations
"array-type": [true, "array"],
"arrow-return-shorthand": false,
"await-promise": false,
"adjacent-overload-signatures": false,
"align": [
false
],
"arrow-parens": false,
"ban": false,
"callable-types": true,
"chai-prefer-contains-to-index-of": true,
"chai-vague-errors": true,
"class-name": true,
"comment-format": [
false
],
"completed-docs": [
false
],
"curly": true,
"cyclomatic-complexity": [
false
],
"eofline": false,
"export-name": true,
"file-header": [
false
],
"forin": true,
"function-name": true,
"import-blacklist": false,
"import-name": true,
"import-spacing": true,
"informative-docs": true,
"indent": [
true,
"spaces"
],
"insecure-random": true,
"interface-name": false,
"interface-over-type-literal": false,
"jquery-deferred-must-complete": true,
"jsdoc-format": false,
"label-position": true,
"linebreak-style": [
true,
"LF"
],
"max-classes-per-file": [
false
],
"max-file-line-count": [
false
],
"max-func-body-length": [
true,
100,
{
"ignore-parameters-to-function-regex": "^describe$"
}
],
"max-line-length": [
true,
140
],
"member-access": true,
"member-ordering": [
false
],
"missing-jsdoc": false,
"missing-optional-annotation": false,
"mocha-avoid-only": true,
"mocha-no-side-effect-code": true,
"mocha-unneeded-done": true,
"new-parens": true,
"no-angle-bracket-type-assertion": false,
"no-any": true,
"no-arg": true,
"no-backbone-get-set-outside-model": true,
"no-banned-terms": true,
"no-bitwise": true,
"no-boolean-literal-compare": false,
"no-conditional-assignment": true,
"no-consecutive-blank-lines": [
true
],
"no-console": [
true,
"debug",
@ -99,159 +20,15 @@
"timeEnd",
"trace"
],
"no-constant-condition": true,
"no-construct": true,
"no-control-regex": true,
"no-cookies": true,
"no-debugger": true,
"no-default-export": true,
"no-delete-expression": true,
"no-disable-auto-sanitization": true,
"no-document-domain": true,
"no-document-write": true,
"no-duplicate-case": false,
"no-duplicate-parameter-names": false,
"no-duplicate-super": true,
"no-duplicate-variable": true,
"no-empty": true,
"no-empty-interface": true,
"no-empty-interfaces": false,
"no-empty-line-after-opening-brace": false,
"no-eval": true,
"no-exec-script": true,
"no-floating-promises": false,
"no-for-in": true,
"no-for-in-array": false,
"no-function-constructor-with-string-args": true,
"no-function-expression": true,
"no-http-string": [
true,
"http://www.example.com/?.*",
"http://www.examples.com/?.*"
],
"no-import-side-effect": true,
"no-increment-decrement": true,
"no-inferrable-types": false,
"no-inferred-empty-object-type": false,
"no-inner-html": true,
"no-internal-module": false,
"no-invalid-regexp": true,
"no-invalid-template-strings": true,
"no-invalid-this": true,
"no-jquery-raw-elements": true,
"no-magic-numbers": false,
"no-mergeable-namespace": false,
"no-missing-visibility-modifiers": false,
"no-misused-new": true,
"no-multiline-string": [ false ],
"no-multiple-var-decl": false,
"no-namespace": false,
"no-null-keyword": true,
"no-octal-literal": true,
"no-parameter-properties": false,
"no-reference": true,
"no-reference-import": true,
"no-regex-spaces": true,
"no-require-imports": true,
"no-reserved-keywords": true,
"no-shadowed-variable": true,
"no-single-line-block-comment": true,
"no-sparse-arrays": true,
"no-stateless-class": false,
"no-string-based-set-immediate": true,
"no-string-based-set-interval": true,
"no-string-based-set-timeout": true,
"no-string-literal": true,
"no-string-throw": true,
"no-suspicious-comment": true,
"no-switch-case-fall-through": false,
"no-trailing-whitespace": true,
"no-typeof-undefined": true,
"no-unbound-method": false,
"no-unnecessary-bind": true,
"no-unnecessary-callback-wrapper": true,
"no-unnecessary-field-initialization": true,
"no-unnecessary-initializer": true,
"no-unnecessary-local-variable": true,
"no-unnecessary-override": true,
"no-unnecessary-qualifier": false,
"no-unnecessary-semicolons": true,
"no-unsafe-any": false,
"no-unsafe-finally": true,
"no-unsupported-browser-code": false,
"no-unused-expression": true,
"no-use-before-declare": false,
"no-var-keyword": true,
"no-var-requires": true,
"no-var-self": false,
"no-void-expression": false,
"no-with-statement": true,
"non-literal-require": true,
"non-literal-fs-path": true,
"object-literal-key-quotes": [
true,
"as-needed"
],
"object-literal-shorthand": false,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"one-variable-per-declaration": true,
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
"ordered-imports": [
false
],
"possible-timing-attack": true,
"prefer-array-literal": true,
"prefer-const": true,
"prefer-for-of": false,
"prefer-function-over-method": false,
"prefer-method-signature": true,
"prefer-readonly": true,
"prefer-template": false,
"prefer-type-cast": true,
"strict-type-predicates": false,
"promise-function-async": false,
"promise-must-complete": true,
"quotemark": [
true,
"single"
],
"radix": false,
"react-a11y-anchors": true,
"react-a11y-aria-unsupported-elements": true,
"react-a11y-event-has-role": true,
"react-a11y-image-button-has-alt": true,
"react-a11y-img-has-alt": true,
"react-a11y-lang": true,
"react-a11y-meta": true,
"react-a11y-no-onchange": true,
"react-a11y-props": true,
"react-a11y-proptypes": true,
"react-a11y-role": true,
"react-a11y-role-has-required-aria-props": true,
"react-a11y-role-supports-aria-props": true,
"react-a11y-tabindex-no-positive": true,
"react-a11y-titles": true,
"react-anchor-blank-noopener": true,
"react-iframe-missing-sandbox": true,
"react-no-dangerous-html": true,
"react-this-binding-issue": true,
"react-tsx-curly-spacing": false,
"react-unused-props-and-state": true,
"restrict-plus-operands": false,
"semicolon": [
true,
"ignore-bound-class-methods"
],
"space-before-function-paren": false,
"strict-boolean-expressions": false,
"switch-default": false,
"trailing-comma": [
true,
{
@ -263,22 +40,6 @@
true,
"allow-null-check"
],
"typedef": [
true,
"parameter",
"property-declaration",
"member-variable-declaration"
],
"typedef-whitespace": [
false
],
"typeof-compare": false,
"underscore-consistent-invocation": true,
"unified-signatures": true,
"use-isnan": true,
"use-named-parameter": true,
"valid-typeof": false,
"variable-name": true,
"whitespace": [
true,
"check-branch",
@ -287,32 +48,174 @@
"check-separator",
"check-type"
],
"no-useless-files": true,
// Core rules we plan on enabling
// See https://github.com/Microsoft/tslint-microsoft-contrib/issues/491
"align": false,
"ban-types": false,
"deprecation": false,
"eofline": false,
"jsdoc-format": false,
"member-access": false,
"no-any": false,
"no-boolean-literal-compare": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-namespace": false,
"no-non-null-assertion": false,
"no-unbound-method": false,
"no-unsafe-any": false,
"prefer-for-of": false,
"prefer-function-over-method": false,
"restrict-plus-operands": false,
"strict-boolean-expressions": false,
"strict-type-predicates": false,
// Core rules intentionally disabled
"arrow-parens": false,
"arrow-return-shorthand": false,
"comment-format": false,
"completed-docs": false,
"cyclomatic-complexity": false,
"file-name-casing": false,
"interface-name": false,
"max-classes-per-file": false,
"max-file-line-count": false,
"member-ordering": false,
"newline-before-return": false,
"newline-per-chained-call": false,
"no-angle-bracket-type-assertion": false,
"no-magic-numbers": false,
"no-unnecessary-qualifier": false,
"no-unused-variable": false,
"no-use-before-declare": false,
"interface-over-type-literal": false,
"object-literal-shorthand": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"prefer-template": false,
"space-before-function-name": false,
"space-before-function-paren": false,
"typedef": false,
"typedef-whitespace": false,
// tslint-microsoft-contrib rules enabled
"ban-comma-operator": true,
"binary-expression-operand-order": false,
"deprecation": false,
"chai-prefer-contains-to-index-of": true,
"chai-vague-errors": true,
"encoding": true,
"export-name": true,
"function-name": true,
"import-name": true,
"informative-docs": true,
"insecure-random": true,
"jquery-deferred-must-complete": true,
"max-func-body-length": true,
"missing-optional-annotation": true,
"mocha-avoid-only": true,
"mocha-no-side-effect-code": true,
"mocha-unneeded-done": true,
"no-backbone-get-set-outside-model": true,
"no-banned-terms": true,
"no-constant-condition": true,
"no-control-regex": true,
"no-cookies": true,
"no-delete-expression": true,
"no-disable-auto-sanitization": true,
"no-document-domain": true,
"no-document-write": true,
"no-duplicate-imports": true,
"no-duplicate-parameter-names": true,
"no-duplicate-switch-case": true,
"no-exec-script": true,
"no-for-in": true,
"no-function-constructor-with-string-args": true,
"no-function-expression": true,
"no-http-string": true,
"no-implicit-dependencies": true,
"no-increment-decrement": true,
"no-inner-html": true,
"no-invalid-regexp": true,
"no-irregular-whitespace": true,
"no-jquery-raw-elements": true,
"no-missing-visibility-modifiers": true,
"no-multiple-var-decl": true,
"no-object-literal-type-assertion": true,
"no-octal-literal": true,
"no-parameter-reassignment": false,
"no-redundant-jsdoc": true,
"no-regex-spaces": true,
"no-reserved-keywords": true,
"no-return-await": true,
"no-single-line-block-comment": true,
"no-string-based-set-immediate": true,
"no-string-based-set-interval": true,
"no-string-based-set-timeout": true,
"no-submodule-imports": true,
"no-suspicious-comment": true,
"no-this-assignment": true,
"no-typeof-undefined": true,
"no-unnecessary-bind": true,
"no-unnecessary-class": true,
"no-unnecessary-field-initialization": true,
"no-unnecessary-local-variable": true,
"no-unnecessary-override": true,
"no-unnecessary-semicolons": true,
"no-unnecessary-type-assertion": false,
"no-unsupported-browser-code": true,
"no-useless-files": true,
"no-with-statement": true,
"non-literal-fs-path": true,
"non-literal-require": true,
"number-literal-format": true,
"possible-timing-attack": true,
"prefer-array-literal": true,
"prefer-conditional-expression": false,
"prefer-object-spread": true,
"prefer-switch": false,
"prefer-type-cast": true,
"promise-must-complete": true,
"react-a11y-anchors": true,
"react-a11y-aria-unsupported-elements": true,
"react-a11y-event-has-role": true,
"react-a11y-image-button-has-alt": true,
"react-a11y-img-has-alt": true,
"react-a11y-input-elements": true,
"react-a11y-lang": true,
"react-a11y-meta": true,
"react-a11y-no-onchange": true,
"react-a11y-props": true,
"react-a11y-proptypes": true,
"react-a11y-required": true,
"react-a11y-role-has-required-aria-props": true,
"react-a11y-role-supports-aria-props": true,
"react-a11y-role": true,
"react-a11y-tabindex-no-positive": true,
"react-a11y-titles": true,
"react-anchor-blank-noopener": true,
"react-iframe-missing-sandbox": true,
"react-no-dangerous-html": true,
"react-this-binding-issue": true,
"react-unused-props-and-state": true,
"space-within-parens": true,
"switch-final-break": true,
"type-literal-delimiter": false,
"underscore-consistent-invocation": true,
"use-default-type-parameter": false,
"react-a11y-input-elements": true,
"react-a11y-required": true
"use-named-parameter": true,
// tslint-microsoft-contrib rules disabled
"missing-jsdoc": false,
"no-duplicate-case": false,
"no-empty-interfaces": false,
"no-empty-line-after-opening-brace": false,
"no-multiline-string": false,
"no-relative-imports": false,
"no-stateless-class": false,
"no-unexternalized-strings": false,
"no-var-self": false,
"react-tsx-curly-spacing": false,
"valid-typeof": false
}
}