diff --git a/README.md b/README.md index f825495d2..ec47006ce 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,6 @@ Rule Name | Description | Since `no-relative-imports` | Do not use relative paths when importing external modules or ES6 import declarations. The advantages of removing all relative paths from imports is that 1) the import name will be consistent across all files and subdirectories so searching for usages is much easier. 2) Moving source files to different folders will not require you to edit your import statements. 3) It will be possible to copy and paste import lines between files regardless of the file location. And 4) version control diffs will be simplified by having overall fewer edits to the import lines.| 2.0.5 `no-reserved-keywords` | Do not use reserved keywords as names of local variables, fields, functions, or other identifiers. Since version 2.0.9 this rule accepts a parameter called allow-quoted-properties. If true, interface properties in quotes will be ignored. This can be a useful way to avoid verbose suppress-warning comments for generated d.ts files.| 0.0.1, 2.0.9 `no-single-line-block-comment` | Avoid single line block comments and use single line comments instead. Block comments do not nest properly and have no advantages over normal single-line comments| 2.0.10 -`no-sparse-arrays` | Do not use sparse arrays. Sparse arrays contain empty slots, most frequently due to multiple commas being used in an array literal. Based on the [ESLint no-sparse-arrays](http://eslint.org/docs/rules/no-sparse-arrays) rule | 1.0 `no-stateless-class` | A stateless class represents a failure in the object oriented design of the system. A class without state is better modeled as a module or given some state. A stateless class is defined as a class with only static members and no parent class.| 2.0.4 `no-string-based-set-immediate` | Do not use the version of setImmediate that accepts code as a string argument. However, it is acceptable to use the version of setImmediate where a direct reference to a function is provided as the callback argument | 0.0.1 `no-string-based-set-interval` | Do not use the version of setInterval that accepts code as a string argument. However, it is acceptable to use the version of setInterval where a direct reference to a function is provided as the callback argument | 0.0.1 diff --git a/src/noSparseArraysRule.ts b/src/noSparseArraysRule.ts deleted file mode 100644 index 5b348169a..000000000 --- a/src/noSparseArraysRule.ts +++ /dev/null @@ -1,52 +0,0 @@ -import * as ts from 'typescript'; -import * as Lint from 'tslint'; - -import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker'; -import {Utils} from './utils/Utils'; -import {ExtendedMetadata} from './utils/ExtendedMetadata'; - -/** - * Implementation of the no-sparse-arrays rule. - */ -export class Rule extends Lint.Rules.AbstractRule { - - public static metadata: ExtendedMetadata = { - ruleName: 'no-sparse-arrays', - type: 'maintainability', - description: 'Do not use sparse arrays. Sparse arrays contain empty slots, most frequently due to multiple ' + - 'commas being used in an array literal.', - options: null, - optionsDescription: '', - typescriptOnly: true, - issueClass: 'Non-SDL', - issueType: 'Warning', - severity: 'Important', - level: 'Opportunity for Excellence', - group: 'Correctness', - commonWeaknessEnumeration: '398, 710' - }; - - public static FAILURE_STRING: string = 'Unexpected comma in middle of array'; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NoSparseArraysRuleWalker(sourceFile, this.getOptions())); - } - -} - -class NoSparseArraysRuleWalker extends ErrorTolerantWalker { - protected visitNode(node: ts.Node): void { - if (node.kind === ts.SyntaxKind.ArrayLiteralExpression) { - if (this.isSparseArray(node)) { - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); - } - } - super.visitNode(node); - } - - private isSparseArray(node: ts.ArrayLiteralExpression): boolean { - return Utils.exists(node.elements, (element: ts.Node): boolean => { - return element.kind === ts.SyntaxKind.OmittedExpression; - }); - } -} diff --git a/src/tests/NoSparseArraysRuleTests.ts b/src/tests/NoSparseArraysRuleTests.ts deleted file mode 100644 index 573002bbc..000000000 --- a/src/tests/NoSparseArraysRuleTests.ts +++ /dev/null @@ -1,73 +0,0 @@ -import {TestHelper} from './TestHelper'; - -/** - * Unit tests. - */ -describe('noSparseArraysRule', () : void => { - const ruleName : string = 'no-sparse-arrays'; - - it('should pass on dense arrays', () : void => { - const script : string = ` - var a = []; - var b = [1]; - var c = ['1', '2']; - var d = [true, false, true]; - var e = [1,2,3,]; // dangling comma is not an issue - `; - - TestHelper.assertViolations(ruleName, script, [ ]); - }); - - it('should fail on comma with no elements', () : void => { - const script : string = ` - var x = [,]; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - "failure": "Unexpected comma in middle of array", - "name": "file.ts", - "ruleName": "no-sparse-arrays", - "startPosition": { "character": 21, "line": 2 } - } - ]); - }); - - it('should fail on array with many commas', () : void => { - const script : string = ` - var x = [,,,]; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - "failure": "Unexpected comma in middle of array", - "name": "file.ts", - "ruleName": "no-sparse-arrays", - "startPosition": { "character": 21, "line": 2 } - } - ]); - }); - - it('should fail on array with elements and commas', () : void => { - const script : string = ` - var x = [,1,2,3]; - var z = [1,,2,3]; - `; - - TestHelper.assertViolations(ruleName, script, [ - { - "failure": "Unexpected comma in middle of array", - "name": "file.ts", - "ruleName": "no-sparse-arrays", - "startPosition": { "character": 21, "line": 2 } - }, - { - "failure": "Unexpected comma in middle of array", - "name": "file.ts", - "ruleName": "no-sparse-arrays", - "startPosition": { "character": 21, "line": 3 } - } - ]); - }); - -}); \ No newline at end of file