aboutsummaryrefslogtreecommitdiffstats
path: root/packages/tslint-config
diff options
context:
space:
mode:
authorHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
committerHsuan Lee <boczeratul@gmail.com>2019-03-06 17:46:50 +0800
commit35703539d0f2b4ddb3b11d0de8c9634af59ab71f (patch)
treeae3731221dbbb3a6fa40060a8d916cfd3f738289 /packages/tslint-config
parent92a1fde5b1ecd81b07cdb5bf0c9c1cd3544799db (diff)
downloaddexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.gz
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.zst
dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.zip
Deploy @dexon-foundation/0x.jsstable
Diffstat (limited to 'packages/tslint-config')
-rw-r--r--packages/tslint-config/.npmignore7
-rw-r--r--packages/tslint-config/CHANGELOG.json284
-rw-r--r--packages/tslint-config/CHANGELOG.md128
-rw-r--r--packages/tslint-config/README.md71
-rw-r--r--packages/tslint-config/package.json52
-rw-r--r--packages/tslint-config/rules/asyncSuffixRule.ts10
-rw-r--r--packages/tslint-config/rules/booleanNamingRule.ts69
-rw-r--r--packages/tslint-config/rules/customNoMagicNumbersRule.ts79
-rw-r--r--packages/tslint-config/rules/enumNamingRule.ts60
-rw-r--r--packages/tslint-config/rules/underscorePrivateAndProtectedRule.ts61
-rw-r--r--packages/tslint-config/rules/walkers/async_suffix.ts35
-rw-r--r--packages/tslint-config/test/enumNamingSpec.spec.ts88
-rw-r--r--packages/tslint-config/test/lintrunner.ts23
-rw-r--r--packages/tslint-config/tsconfig.json8
-rw-r--r--packages/tslint-config/tslint.json130
15 files changed, 0 insertions, 1105 deletions
diff --git a/packages/tslint-config/.npmignore b/packages/tslint-config/.npmignore
deleted file mode 100644
index c46793a87..000000000
--- a/packages/tslint-config/.npmignore
+++ /dev/null
@@ -1,7 +0,0 @@
-.*
-yarn-error.log
-node_modules/
-/scripts/
-/rules/
-tsconfig.json
-/lib/monorepo_scripts/
diff --git a/packages/tslint-config/CHANGELOG.json b/packages/tslint-config/CHANGELOG.json
deleted file mode 100644
index 884a5b46f..000000000
--- a/packages/tslint-config/CHANGELOG.json
+++ /dev/null
@@ -1,284 +0,0 @@
-[
- {
- "version": "3.0.0",
- "changes": [
- {
- "note": "Upgrade the bignumber.js to v8.0.2",
- "pr": 1517
- }
- ],
- "timestamp": 1549373905
- },
- {
- "timestamp": 1547561734,
- "version": "2.0.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1547225310,
- "version": "2.0.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "2.0.0",
- "changes": [
- {
- "note": "Improve async-suffix rule to check functions too, not just methods",
- "pr": 1425
- }
- ],
- "timestamp": 1544739608
- },
- {
- "version": "1.0.10",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ],
- "timestamp": 1541740904
- },
- {
- "timestamp": 1539871071,
- "version": "1.0.9",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1538693146,
- "version": "1.0.8",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1536142250,
- "version": "1.0.7",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1535133899,
- "version": "1.0.6",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1534210131,
- "version": "1.0.5",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532614997,
- "version": "1.0.4",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532605697,
- "version": "1.0.3",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532551340,
- "version": "1.0.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532357734,
- "version": "1.0.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532043000,
- "version": "1.0.0",
- "changes": [
- {
- "note": "Added a bunch of rules",
- "pr": 883
- }
- ]
- },
- {
- "timestamp": 1531149657,
- "version": "0.4.21",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1529397769,
- "version": "0.4.20",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.4.19",
- "changes": [
- {
- "note": "Incorrect publish that was unpublished"
- }
- ],
- "timestamp": 1527810075
- },
- {
- "timestamp": 1527009133,
- "version": "0.4.18",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1525428773,
- "version": "0.4.17",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1524044013,
- "version": "0.4.16",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1523462196,
- "version": "0.4.15",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1522673609,
- "version": "0.4.14",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1522658513,
- "version": "0.4.13",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.4.9",
- "changes": [
- {
- "note": "Move devDeps to deps to fix missed dependency issue in published package."
- }
- ],
- "timestamp": 1518102000
- },
- {
- "version": "0.4.8",
- "changes": [
- {
- "note": "Fix publish issue where custom TSLint rules were not being included",
- "pr": 389
- }
- ],
- "timestamp": 1518102000
- },
- {
- "version": "0.4.7",
- "changes": [
- {
- "note": "Modified custom 'underscore-privates' rule, changing it to 'underscore-private-and-protected' requiring underscores to be prepended to both private and protected variable names",
- "pr": 354
- }
- ],
- "timestamp": 1517929200
- },
- {
- "version": "0.4.0",
- "changes": [
- {
- "note": "Added custom 'underscore-privates' rule, requiring underscores to be prepended to private variable names"
- },
- {
- "note": "Because our tools can be used in both a TS and JS environment, we want to make the private methods of any public facing interface show up at the bottom of auto-complete lists. Additionally, we wanted to remain consistent with respect to our usage of underscores in order to enforce this rule with a linter rule, rather then manual code reviews."
- }
- ],
- "timestamp": 1514386800
- },
- {
- "version": "0.3.0",
- "changes": [
- {
- "note": "Added rules for unused imports, variables and Async suffixes",
- "pr": 265
- }
- ],
- "timestamp": 1513695600
- },
- {
- "version": "0.1.0",
- "changes": [
- {
- "note": "Re-published TsLintConfig previously published under NPM package `tslint-config-0xproject`"
- },
- {
- "note": "Updated to TSLint v5.8.0, requiring several rule additions to keep our conventions aligned."
- }
- ],
- "timestamp": 1510585200
- }
-]
diff --git a/packages/tslint-config/CHANGELOG.md b/packages/tslint-config/CHANGELOG.md
deleted file mode 100644
index 5719f28a6..000000000
--- a/packages/tslint-config/CHANGELOG.md
+++ /dev/null
@@ -1,128 +0,0 @@
-<!--
-changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
-Edit the package's CHANGELOG.json file only.
--->
-
-CHANGELOG
-
-## v3.0.0 - _February 5, 2019_
-
- * Upgrade the bignumber.js to v8.0.2 (#1517)
-
-## v2.0.2 - _January 15, 2019_
-
- * Dependencies updated
-
-## v2.0.1 - _January 11, 2019_
-
- * Dependencies updated
-
-## v2.0.0 - _December 13, 2018_
-
- * Improve async-suffix rule to check functions too, not just methods (#1425)
-
-## v1.0.10 - _November 9, 2018_
-
- * Dependencies updated
-
-## v1.0.9 - _October 18, 2018_
-
- * Dependencies updated
-
-## v1.0.8 - _October 4, 2018_
-
- * Dependencies updated
-
-## v1.0.7 - _September 5, 2018_
-
- * Dependencies updated
-
-## v1.0.6 - _August 24, 2018_
-
- * Dependencies updated
-
-## v1.0.5 - _August 14, 2018_
-
- * Dependencies updated
-
-## v1.0.4 - _July 26, 2018_
-
- * Dependencies updated
-
-## v1.0.3 - _July 26, 2018_
-
- * Dependencies updated
-
-## v1.0.2 - _July 25, 2018_
-
- * Dependencies updated
-
-## v1.0.1 - _July 23, 2018_
-
- * Dependencies updated
-
-## v1.0.0 - _July 19, 2018_
-
- * Added a bunch of rules (#883)
-
-## v0.4.21 - _July 9, 2018_
-
- * Dependencies updated
-
-## v0.4.20 - _June 19, 2018_
-
- * Dependencies updated
-
-## v0.4.19 - _May 31, 2018_
-
- * Incorrect publish that was unpublished
-
-## v0.4.18 - _May 22, 2018_
-
- * Dependencies updated
-
-## v0.4.17 - _May 4, 2018_
-
- * Dependencies updated
-
-## v0.4.16 - _April 18, 2018_
-
- * Dependencies updated
-
-## v0.4.15 - _April 11, 2018_
-
- * Dependencies updated
-
-## v0.4.14 - _April 2, 2018_
-
- * Dependencies updated
-
-## v0.4.13 - _April 2, 2018_
-
- * Dependencies updated
-
-## v0.4.9 - _February 8, 2018_
-
- * Move devDeps to deps to fix missed dependency issue in published package.
-
-## v0.4.8 - _February 8, 2018_
-
- * Fix publish issue where custom TSLint rules were not being included (#389)
-
-## v0.4.7 - _February 6, 2018_
-
- * Modified custom 'underscore-privates' rule, changing it to 'underscore-private-and-protected' requiring underscores to be prepended to both private and protected variable names (#354)
-
-## v0.4.0 - _December 27, 2017_
-
- * Added custom 'underscore-privates' rule, requiring underscores to be prepended to private variable names
- * Because our tools can be used in both a TS and JS environment, we want to make the private methods of any public facing interface show up at the bottom of auto-complete lists. Additionally, we wanted to remain consistent with respect to our usage of underscores in order to enforce this rule with a linter rule, rather then manual code reviews.
-
-## v0.3.0 - _December 19, 2017_
-
- * Added rules for unused imports, variables and Async suffixes (#265)
-
-## v0.1.0 - _November 13, 2017_
-
- * Re-published TsLintConfig previously published under NPM package `tslint-config-0xproject`
- * Updated to TSLint v5.8.0, requiring several rule additions to keep our conventions aligned.
diff --git a/packages/tslint-config/README.md b/packages/tslint-config/README.md
deleted file mode 100644
index 5614e5e54..000000000
--- a/packages/tslint-config/README.md
+++ /dev/null
@@ -1,71 +0,0 @@
-## @0x/tslint-config
-
-TSLint configuration and custom linter rules used by 0xProject.
-
-## Installation
-
-```bash
-yarn add --dev @0x/tslint-config
-```
-
-## Usage
-
-Add the following to your `tslint.json` file
-
-```json
-{
- "extends": ["@0x/tslint-config"]
-}
-```
-
-## Contributing
-
-We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
-
-Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
-
-### Install dependencies
-
-If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
-
-```bash
-yarn config set workspaces-experimental true
-```
-
-Then install dependencies
-
-```bash
-yarn install
-```
-
-### Build
-
-To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:
-
-```bash
-PKG=@0x/tslint-config yarn build
-```
-
-Or continuously rebuild on change:
-
-```bash
-PKG=@0x/tslint-config yarn watch
-```
-
-### Clean
-
-```bash
-yarn clean
-```
-
-### Lint
-
-```bash
-yarn lint
-```
-
-### Run Tests
-
-```bash
-yarn test
-```
diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json
deleted file mode 100644
index b5846a5aa..000000000
--- a/packages/tslint-config/package.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
- "name": "@0x/tslint-config",
- "version": "3.0.0",
- "engines": {
- "node": ">=6.12"
- },
- "description": "Lint rules related to 0xProject for TSLint",
- "main": "tslint.json",
- "scripts": {
- "build": "tsc -b",
- "build:ci": "yarn build",
- "test": "mocha ./lib/test/*.spec.js",
- "clean": "shx rm -rf lib",
- "lint": "tslint --format stylish --project ."
- },
- "repository": {
- "type": "git",
- "url": "git://github.com/0xProject/0x-monorepo.git"
- },
- "keywords": [
- "tslint",
- "config",
- "0xProject",
- "typescript",
- "ts"
- ],
- "author": {
- "name": "Fabio Berger",
- "email": "fabio@0xproject.com"
- },
- "license": "Apache-2.0",
- "bugs": {
- "url": "https://github.com/0xProject/0x-monorepo/issues"
- },
- "homepage": "https://github.com/0xProject/0x-monorepo/packages/tslint-config/README.md",
- "devDependencies": {
- "@types/lodash": "4.14.104",
- "make-promises-safe": "^1.1.0",
- "shx": "^0.2.2",
- "typescript": "3.0.1"
- },
- "dependencies": {
- "lodash": "^4.17.11",
- "tslint": "5.11.0",
- "tslint-eslint-rules": "5.4.0",
- "tslint-react": "^3.2.0",
- "tsutils": "3.0.0"
- },
- "publishConfig": {
- "access": "public"
- }
-}
diff --git a/packages/tslint-config/rules/asyncSuffixRule.ts b/packages/tslint-config/rules/asyncSuffixRule.ts
deleted file mode 100644
index 5215c7151..000000000
--- a/packages/tslint-config/rules/asyncSuffixRule.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import * as Lint from 'tslint';
-import * as ts from 'typescript';
-
-import { AsyncSuffixWalker } from './walkers/async_suffix';
-
-export class Rule extends Lint.Rules.AbstractRule {
- public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
- return this.applyWithWalker(new AsyncSuffixWalker(sourceFile, this.getOptions()));
- }
-}
diff --git a/packages/tslint-config/rules/booleanNamingRule.ts b/packages/tslint-config/rules/booleanNamingRule.ts
deleted file mode 100644
index 6590f689b..000000000
--- a/packages/tslint-config/rules/booleanNamingRule.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import * as _ from 'lodash';
-import * as Lint from 'tslint';
-import * as ts from 'typescript';
-
-const VALID_BOOLEAN_PREFIXES = ['is', 'does', 'should', 'was', 'has', 'can', 'did', 'would', 'are'];
-// tslint:disable:no-unnecessary-type-assertion
-export class Rule extends Lint.Rules.TypedRule {
- public static FAILURE_STRING = `Boolean variable names should begin with: ${VALID_BOOLEAN_PREFIXES.join(', ')}`;
-
- public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
- return this.applyWithFunction(sourceFile, walk, undefined, program.getTypeChecker());
- }
-}
-
-function walk(ctx: Lint.WalkContext<void>, tc: ts.TypeChecker): void {
- traverse(ctx.sourceFile);
-
- function traverse(node: ts.Node): void {
- checkNodeForViolations(ctx, node, tc);
- return ts.forEachChild(node, traverse);
- }
-}
-
-function checkNodeForViolations(ctx: Lint.WalkContext<void>, node: ts.Node, tc: ts.TypeChecker): void {
- switch (node.kind) {
- // Handle: const { timestamp } = ...
- case ts.SyntaxKind.BindingElement: {
- const bindingElementNode = node as ts.BindingElement;
- if (bindingElementNode.name.kind === ts.SyntaxKind.Identifier) {
- handleBooleanNaming(bindingElementNode, tc, ctx);
- }
- break;
- }
-
- // Handle regular assignments: const block = ...
- case ts.SyntaxKind.VariableDeclaration:
- const variableDeclarationNode = node as ts.VariableDeclaration;
- if (variableDeclarationNode.name.kind === ts.SyntaxKind.Identifier) {
- handleBooleanNaming(node as ts.VariableDeclaration, tc, ctx);
- }
- break;
-
- default:
- _.noop();
- }
-}
-
-function handleBooleanNaming(
- node: ts.VariableDeclaration | ts.BindingElement,
- tc: ts.TypeChecker,
- ctx: Lint.WalkContext<void>,
-): void {
- const nodeName = node.name;
- const variableName = nodeName.getText();
- const lowercasedName = _.toLower(variableName);
- const typeNode = tc.getTypeAtLocation(node);
- const typeName = (typeNode as any).intrinsicName;
- if (typeName === 'boolean') {
- const hasProperName = !_.isUndefined(
- _.find(VALID_BOOLEAN_PREFIXES, prefix => {
- return _.startsWith(lowercasedName, prefix);
- }),
- );
- if (!hasProperName) {
- ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
- }
- }
-}
-// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/tslint-config/rules/customNoMagicNumbersRule.ts b/packages/tslint-config/rules/customNoMagicNumbersRule.ts
deleted file mode 100644
index cb124f738..000000000
--- a/packages/tslint-config/rules/customNoMagicNumbersRule.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import * as Lint from 'tslint';
-import { isPrefixUnaryExpression } from 'tsutils';
-import * as ts from 'typescript';
-
-// tslint:disable:no-unnecessary-type-assertion
-/**
- * A modified version of the no-magic-numbers rule that allows for magic numbers
- * when instantiating a BigNumber instance.
- * E.g We want to be able to write:
- * const amount = new BigNumber(5);
- * Original source: https://github.com/palantir/tslint/blob/42b058a6baa688f8be8558b277eb056c3ff79818/src/rules/noMagicNumbersRule.ts
- */
-export class Rule extends Lint.Rules.AbstractRule {
- public static ALLOWED_NODES = new Set<ts.SyntaxKind>([
- ts.SyntaxKind.ExportAssignment,
- ts.SyntaxKind.FirstAssignment,
- ts.SyntaxKind.LastAssignment,
- ts.SyntaxKind.PropertyAssignment,
- ts.SyntaxKind.ShorthandPropertyAssignment,
- ts.SyntaxKind.VariableDeclaration,
- ts.SyntaxKind.VariableDeclarationList,
- ts.SyntaxKind.EnumMember,
- ts.SyntaxKind.PropertyDeclaration,
- ts.SyntaxKind.Parameter,
- ]);
-
- public static DEFAULT_ALLOWED = [-1, 0, 1];
-
- public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
- const allowedNumbers = this.ruleArguments.length > 0 ? this.ruleArguments : Rule.DEFAULT_ALLOWED;
- return this.applyWithWalker(
- // tslint:disable-next-line:no-inferred-empty-object-type
- new CustomNoMagicNumbersWalker(sourceFile, this.ruleName, new Set(allowedNumbers.map(String))),
- );
- }
-}
-
-// tslint:disable-next-line:max-classes-per-file
-class CustomNoMagicNumbersWalker extends Lint.AbstractWalker<Set<string>> {
- public static FAILURE_STRING = "'magic numbers' are not allowed";
- private static _isNegativeNumberLiteral(
- node: ts.Node,
- ): node is ts.PrefixUnaryExpression & { operand: ts.NumericLiteral } {
- return (
- isPrefixUnaryExpression(node) &&
- node.operator === ts.SyntaxKind.MinusToken &&
- node.operand.kind === ts.SyntaxKind.NumericLiteral
- );
- }
- public walk(sourceFile: ts.SourceFile): void {
- const cb = (node: ts.Node): void => {
- if (node.kind === ts.SyntaxKind.NumericLiteral) {
- return this.checkNumericLiteral(node, (node as ts.NumericLiteral).text);
- }
- if (CustomNoMagicNumbersWalker._isNegativeNumberLiteral(node)) {
- return this.checkNumericLiteral(node, `-${(node.operand as ts.NumericLiteral).text}`);
- }
- return ts.forEachChild(node, cb);
- };
- return ts.forEachChild(sourceFile, cb);
- }
-
- // tslint:disable:no-non-null-assertion
- // tslint:disable-next-line:underscore-private-and-protected
- private checkNumericLiteral(node: ts.Node, num: string): void {
- if (!Rule.ALLOWED_NODES.has(node.parent!.kind) && !this.options.has(num)) {
- if (node.parent!.kind === ts.SyntaxKind.NewExpression) {
- const className = (node.parent! as any).expression.escapedText;
- const BIG_NUMBER_NEW_EXPRESSION = 'BigNumber';
- if (className === BIG_NUMBER_NEW_EXPRESSION) {
- return; // noop
- }
- }
- this.addFailureAtNode(node, CustomNoMagicNumbersWalker.FAILURE_STRING);
- }
- }
- // tslint:enable:no-non-null-assertion
-}
-// tslint:enable:no-unnecessary-type-assertion
diff --git a/packages/tslint-config/rules/enumNamingRule.ts b/packages/tslint-config/rules/enumNamingRule.ts
deleted file mode 100644
index 56499618f..000000000
--- a/packages/tslint-config/rules/enumNamingRule.ts
+++ /dev/null
@@ -1,60 +0,0 @@
-import * as Lint from 'tslint';
-import * as ts from 'typescript';
-
-export class Rule extends Lint.Rules.AbstractRule {
- public static FAILURE_STRING = `Enum member names should be PascalCase`;
-
- public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
- return this.applyWithFunction(sourceFile, walk);
- }
-}
-
-function walk(ctx: Lint.WalkContext<void>): void {
- // Recursively walk the AST starting with root node, `ctx.sourceFile`.
- // Call the function `cb` (defined below) for each child.
- return ts.forEachChild(ctx.sourceFile, cb);
-
- function cb(node: ts.Node): void {
- if (node.kind === ts.SyntaxKind.EnumMember) {
- const keyNode = node.getFirstToken(ctx.sourceFile);
- if (keyNode !== undefined) {
- const keyText = keyNode.getText(ctx.sourceFile);
- if (!isPascalCase(keyText)) {
- return ctx.addFailureAtNode(node, Rule.FAILURE_STRING, getFix(keyText, node));
- }
- }
- }
- // Continue recursion into the AST by calling function `cb` for every child of the current node.
- return ts.forEachChild(node, cb);
- }
-
- function getFix(text: string, node: ts.Node): Lint.Replacement {
- let fix = toPascalCase(text);
- // check for `member = value`
- if (node.getChildCount(ctx.sourceFile) === 3) {
- const value = node.getLastToken(ctx.sourceFile);
- if (value !== undefined) {
- fix += ` = ${value.getText(ctx.sourceFile)}`;
- }
- }
- return new Lint.Replacement(node.getStart(ctx.sourceFile), node.getWidth(ctx.sourceFile), fix);
- }
-}
-
-// Modified from: https://github.com/jonschlinkert/pascalcase/
-function toPascalCase(str: string): string {
- let result = str.replace(/([a-z0-9\W])([A-Z])/g, '$1 $2');
- if (result.length === 1) {
- return result.toUpperCase();
- }
- result = result.replace(/^[\W_\.]+|[\W_\.]+$/g, '').toLowerCase();
- result = result.charAt(0).toUpperCase() + result.slice(1);
- return result.replace(/[\W_\.]+(\w|$)/g, (_, ch) => {
- return ch.toUpperCase();
- });
-}
-function isPascalCase(s: string): boolean {
- const regex = /^([A-Z0-9]+[a-z0-9]+)+$/g;
- const key = s.split('=')[0].trim();
- return regex.test(key);
-}
diff --git a/packages/tslint-config/rules/underscorePrivateAndProtectedRule.ts b/packages/tslint-config/rules/underscorePrivateAndProtectedRule.ts
deleted file mode 100644
index 8c039bea7..000000000
--- a/packages/tslint-config/rules/underscorePrivateAndProtectedRule.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import * as Lint from 'tslint';
-import * as ts from 'typescript';
-
-const UNDERSCORE = '_';
-
-type RelevantClassMember =
- | ts.MethodDeclaration
- | ts.PropertyDeclaration
- | ts.GetAccessorDeclaration
- | ts.SetAccessorDeclaration;
-
-// Copied from: https://github.com/DanielRosenwasser/underscore-privates-tslint-rule
-// The version on github is not published on npm
-export class Rule extends Lint.Rules.AbstractRule {
- public static FAILURE_STRING = 'private and protected members must be prefixed with an underscore';
-
- public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
- return this.applyWithFunction(sourceFile, walk);
- }
-}
-function walk(ctx: Lint.WalkContext<void>): void {
- traverse(ctx.sourceFile);
-
- function traverse(node: ts.Node): void {
- checkNodeForViolations(ctx, node);
- return ts.forEachChild(node, traverse);
- }
-}
-function checkNodeForViolations(ctx: Lint.WalkContext<void>, node: ts.Node): void {
- if (!isRelevantClassMember(node)) {
- return;
- }
- // The declaration might have a computed property name or a numeric name.
- const name = node.name;
- if (!nameIsIdentifier(name)) {
- return;
- }
- if (!nameStartsWithUnderscore(name.text) && memberIsPrivate(node)) {
- ctx.addFailureAtNode(name, Rule.FAILURE_STRING);
- }
-}
-function isRelevantClassMember(node: ts.Node): node is RelevantClassMember {
- switch (node.kind) {
- case ts.SyntaxKind.MethodDeclaration:
- case ts.SyntaxKind.PropertyDeclaration:
- case ts.SyntaxKind.GetAccessor:
- case ts.SyntaxKind.SetAccessor:
- return true;
- default:
- return false;
- }
-}
-function nameStartsWithUnderscore(text: string): boolean {
- return text.charCodeAt(0) === UNDERSCORE.charCodeAt(0);
-}
-function memberIsPrivate(node: ts.Declaration): boolean {
- return Lint.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword);
-}
-function nameIsIdentifier(node: ts.Node): node is ts.Identifier {
- return node.kind === ts.SyntaxKind.Identifier;
-}
diff --git a/packages/tslint-config/rules/walkers/async_suffix.ts b/packages/tslint-config/rules/walkers/async_suffix.ts
deleted file mode 100644
index 4e12152e8..000000000
--- a/packages/tslint-config/rules/walkers/async_suffix.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import * as _ from 'lodash';
-import * as Lint from 'tslint';
-import * as ts from 'typescript';
-
-export class AsyncSuffixWalker extends Lint.RuleWalker {
- public static FAILURE_STRING = 'async functions/methods must have an Async suffix';
- public visitFunctionDeclaration(node: ts.FunctionDeclaration): void {
- this._visitFunctionOrMethodDeclaration(node);
- super.visitFunctionDeclaration(node);
- }
- public visitMethodDeclaration(node: ts.MethodDeclaration): void {
- this._visitFunctionOrMethodDeclaration(node);
- super.visitMethodDeclaration(node);
- }
- private _visitFunctionOrMethodDeclaration(node: ts.MethodDeclaration | ts.FunctionDeclaration): void {
- const nameNode = node.name;
- if (!_.isUndefined(nameNode)) {
- const name = nameNode.getText();
- if (!_.isUndefined(node.type)) {
- if (node.type.kind === ts.SyntaxKind.TypeReference) {
- // tslint:disable-next-line:no-unnecessary-type-assertion
- const returnTypeName = (node.type as ts.TypeReferenceNode).typeName.getText();
- if (returnTypeName === 'Promise' && !name.endsWith('Async')) {
- const failure = this.createFailure(
- nameNode.getStart(),
- nameNode.getWidth(),
- AsyncSuffixWalker.FAILURE_STRING,
- );
- this.addFailure(failure);
- }
- }
- }
- }
- }
-}
diff --git a/packages/tslint-config/test/enumNamingSpec.spec.ts b/packages/tslint-config/test/enumNamingSpec.spec.ts
deleted file mode 100644
index d5b864eba..000000000
--- a/packages/tslint-config/test/enumNamingSpec.spec.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import * as assert from 'assert';
-
-import { Rule } from '../rules/enumNamingRule';
-
-import { getFixedResult, helper } from './lintrunner';
-const rule = 'enum-naming';
-
-describe('enumNamingRule', () => {
- it(`should not fail PascalCase`, () => {
- const src = `enum test { MemberOne, MemberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should not fail PascalCase keys with uncased values`, () => {
- const src = `enum test { MemberOne = 'member_one', MemberTwo = 'member two' }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should not fail PascalCase keys with numbers`, () => {
- const src = `enum test { Member1 = 'member_one', MemberTwo = 'member two' }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 0);
- });
- it(`should fail with camelCase`, () => {
- const src = `enum test { memberOne, memberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with snake case`, () => {
- const src = `enum test { member_one, member_two }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with all caps`, () => {
- const src = `enum test { MEMBERONE, MEMBER_TWO }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 2);
- });
- it(`should fail with mixed case`, () => {
- const src = `enum test { member_one, MemberTwo }`;
- const result = helper(src, rule);
- assert.equal(result.errorCount, 1);
- });
-
- it(`should fail with the right position`, () => {
- const src = `enum test { MemberOne, member_two }`;
- const startPosition = src.indexOf('member_two');
- const endPosition = startPosition + 'member_two'.length;
- const failure = helper(src, rule).failures[0];
-
- assert.equal(failure.getStartPosition().getPosition(), startPosition);
- assert.equal(failure.getEndPosition().getPosition(), endPosition);
- assert.equal(failure.getFailure(), Rule.FAILURE_STRING);
- });
-
- it(`should fail with the right message`, () => {
- const src = `enum test { memberOne, memberTwo }`;
- const failure = helper(src, rule).failures[0];
-
- assert.equal(failure.getFailure(), Rule.FAILURE_STRING);
- });
-});
-describe('enumNaming fixer', () => {
- it('should fix keys', () => {
- const src = `enum test { MemberOne, memberTwo, member_three, MEMBER_FOUR, MEMBERFIVE }`;
- const expected = `enum test { MemberOne, MemberTwo, MemberThree, MemberFour, Memberfive }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 4); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
- it('should not fix values', () => {
- const src = `enum test { MemberOne = 'MemberOne', memberTwo = 'memberTwo', member_three = 'member_three', MEMBER_FOUR = 'MEMBER_FOUR' }`;
- const expected = `enum test { MemberOne = 'MemberOne', MemberTwo = 'memberTwo', MemberThree = 'member_three', MemberFour = 'MEMBER_FOUR' }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 3); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
- it('should preserve values with equals sign', () => {
- const src = `enum Operators { assign = '=', EQUALS = '==', Triple_Equals = '===' }`;
- const expected = `enum Operators { Assign = '=', Equals = '==', TripleEquals = '===' }`;
- const actual = getFixedResult(src, rule);
- const result = helper(src, rule);
- assert.equal(result.errorCount, 3); // tslint:disable-line:custom-no-magic-numbers
- assert.equal(actual, expected);
- });
-});
diff --git a/packages/tslint-config/test/lintrunner.ts b/packages/tslint-config/test/lintrunner.ts
deleted file mode 100644
index fcd1b6844..000000000
--- a/packages/tslint-config/test/lintrunner.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import * as path from 'path';
-import { Configuration, Linter, Replacement } from 'tslint';
-
-export const helper = (src: string, rule: string) => {
- const linter = new Linter({ fix: false });
- linter.lint(
- '',
- src,
- Configuration.parseConfigFile({
- rules: {
- [rule]: true,
- },
- rulesDirectory: path.join(__dirname, '../rules'),
- }),
- );
- return linter.getResult();
-};
-
-export const getFixedResult = (src: string, rule: string) => {
- const result = helper(src, rule);
- const fixes = [].concat.apply(result.failures.map(x => x.getFix()));
- return Replacement.applyFixes(src, fixes);
-};
diff --git a/packages/tslint-config/tsconfig.json b/packages/tslint-config/tsconfig.json
deleted file mode 100644
index b9a4dd03e..000000000
--- a/packages/tslint-config/tsconfig.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "extends": "../../tsconfig",
- "compilerOptions": {
- "outDir": "lib",
- "rootDir": "."
- },
- "include": ["./rules/**/*", "test/**/*"]
-}
diff --git a/packages/tslint-config/tslint.json b/packages/tslint-config/tslint.json
deleted file mode 100644
index a5fa6962c..000000000
--- a/packages/tslint-config/tslint.json
+++ /dev/null
@@ -1,130 +0,0 @@
-{
- "extends": ["tslint:latest", "tslint-react", "tslint-eslint-rules"],
- "rules": {
- "adjacent-overload-signatures": true,
- "arrow-parens": [true, "ban-single-arg-parens"],
- "arrow-return-shorthand": true,
- "async-suffix": true,
- "await-promise": true,
- "binary-expression-operand-order": true,
- "boolean-naming": true,
- "callable-types": true,
- "class-name": true,
- "completed-docs": [
- true,
- {
- "functions": {
- "visibilities": ["exported"]
- },
- "methods": {
- "locations": "instance",
- "privacies": ["public", "protected"]
- }
- }
- ],
- "curly": true,
- "custom-no-magic-numbers": [true, 0, 1, 2, 3, -1],
- "encoding": true,
- "enum-naming": true,
- "eofline": true,
- "import-spacing": true,
- "indent": [true, "spaces", 4],
- "interface-name": false,
- "interface-over-type-literal": true,
- "jsx-alignment": true,
- "jsx-boolean-value": true,
- "jsx-curly-spacing": [true, "never"],
- "jsx-no-bind": false,
- "jsx-no-lambda": true,
- "jsx-no-multiline-js": false,
- "jsx-no-string-ref": true,
- "jsx-self-close": true,
- "jsx-wrap-multiline": false,
- "linebreak-style": [true, "LF"],
- "max-classes-per-file": [true, 1],
- "max-file-line-count": [true, 500],
- "max-line-length": false,
- "member-access": true,
- "member-ordering": [true, "public-before-private", "static-before-instance", "variables-before-functions"],
- "new-parens": true,
- "newline-before-return": false,
- "no-angle-bracket-type-assertion": true,
- "no-boolean-literal-compare": true,
- "no-debugger": true,
- "no-default-export": true,
- "no-duplicate-super": true,
- "no-duplicate-switch-case": true,
- "no-duplicate-variable": true,
- "no-empty-interface": false,
- "no-eval": true,
- "no-floating-promises": true,
- "no-implicit-dependencies": [true, "dev"],
- "no-inferred-empty-object-type": true,
- "no-invalid-template-strings": true,
- "no-invalid-this": true,
- "no-misused-new": true,
- "no-non-null-assertion": true,
- "no-parameter-reassignment": true,
- "no-redundant-jsdoc": true,
- "no-return-await": true,
- "no-shadowed-variable": true,
- "no-sparse-arrays": true,
- "no-string-literal": true,
- "no-string-throw": true,
- "no-submodule-imports": false,
- "no-switch-case-fall-through": true,
- "no-this-assignment": false,
- "no-unbound-method": true,
- "no-unnecessary-class": true,
- "no-unnecessary-type-assertion": true,
- "no-unused-variable": true,
- "no-unsafe-finally": true,
- "number-literal-format": true,
- "object-literal-key-quotes": false,
- "object-literal-sort-keys": false,
- "ordered-imports": [
- true,
- {
- "grouped-imports": true
- }
- ],
- "prefer-const": true,
- "prefer-for-of": true,
- "prefer-function-over-method": true,
- "prefer-object-spread": true,
- "prefer-readonly": true,
- "prefer-template": true,
- "promise-function-async": true,
- "quotemark": [true, "single", "avoid-escape", "jsx-double"],
- "restrict-plus-operands": true,
- "semicolon": [true, "always"],
- "space-before-function-paren": [
- true,
- {
- "anonymous": "never",
- "asyncArrow": "always",
- "constructor": "never",
- "method": "never",
- "named": "never"
- }
- ],
- "space-within-parens": false,
- "switch-default": true,
- "type-literal-delimiter": true,
- "typedef": [true, "call-signature", "parameter", "property-declaration"],
- "underscore-private-and-protected": true,
- "variable-name": [true, "ban-keywords", "allow-pascal-case"],
- "whitespace": [
- true,
- "check-branch",
- "check-decl",
- "check-operator",
- "check-separator",
- "check-rest-spread",
- "check-type",
- "check-typecast",
- "check-preblock"
- ]
- },
- "rulesDirectory": "lib/rules"
-}