diff --git a/package.json b/package.json index d9469578..d6dac8ee 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "build": "tsc -p ./tsconfig.build.json" }, "dependencies": { + "tslint-consistent-codestyle": "^1.5.1", "tslint-eslint-rules": "^4.1.0" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index 8b62db71..ed1a91dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ export = { - extends: ['tslint-eslint-rules'], + extends: ['tslint-eslint-rules', 'tslint-consistent-codestyle'], rules: { // tslint 'adjacent-overload-signatures': true, @@ -18,7 +18,7 @@ export = { ], 'binary-expression-operand-order': true, 'callable-types': true, - 'class-name': true, + 'class-name': false, // tslint-consistent-codestyle: naming-convention 'comment-format': [true, 'check-space'], 'completed-docs': false, curly: true, @@ -31,12 +31,12 @@ export = { 'import-blacklist': false, 'import-spacing': false, // conflict with prettier indent: false, // conflict with prettier - 'interface-name': false, + 'interface-name': false, // tslint-consistent-codestyle: naming-convention 'interface-over-type-literal': true, 'jsdoc-format': true, 'label-position': true, 'linebreak-style': false, // conflict with prettier - 'match-default-export-name': true, + 'match-default-export-name': false, 'max-classes-per-file': [true, 1], 'max-file-line-count': [true, 300], 'max-line-length': false, // conflict with prettier @@ -164,13 +164,7 @@ export = { 'unified-signatures': true, 'use-default-type-parameter': true, 'use-isnan': true, - 'variable-name': [ - true, - 'ban-keywords', - 'check-format', - 'allow-snake-case', - 'allow-leading-underscore', - ], + 'variable-name': [true, 'ban-keywords'], // tslint-consistent-codestyle: naming-convention whitespace: false, // conflict with prettier // tslint-eslint-rules @@ -208,5 +202,37 @@ export = { 'ter-prefer-arrow-callback': false, // tslint: only-arrow-functions 'valid-jsdoc': false, 'valid-typeof': false, // tslint: typeof-compare + + // tslint-consistent-codestyle + 'early-exit': [true], + 'ext-curly': false, + 'naming-convention': [ + true, + { + type: 'default', + format: 'snake_case', + leadingUnderscore: 'forbid', + trailingUnderscore: 'forbid', + }, + { type: 'parameter', leadingUnderscore: 'allow', final: true }, + { type: 'variable', modifiers: 'rename', leadingUnderscore: 'allow' }, + { type: 'member', modifiers: 'private', leadingUnderscore: 'require' }, + { type: 'member', modifiers: 'protected', leadingUnderscore: 'require' }, + { type: 'type', format: 'PascalCase' }, + { type: 'enumMember', format: 'PascalCase' }, + ], + 'no-as-type-assertion': false, + 'no-collapsible-if': true, + 'no-else-after-return': true, + 'no-return-undefined': [true, 'allow-void-expression'], + 'no-static-this': false, + 'no-unnecessary-else': true, + 'no-unused': [true, 'ignore-imports', 'unused-function-expression-name', 'unused-class-expression-name'], + 'no-var-before-return': true, + 'object-shorthand-properties-first': false, + 'oddness-check': false, + 'parameter-properties': false, + 'prefer-const-enum': true, + 'prefer-while': true, }, }; diff --git a/tests/test.ts b/tests/test.ts index e69de29b..be096398 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -0,0 +1,80 @@ +export {}; +// tslint:disable:no-unused-variable no-unused + +declare function do_something(): void; +declare const condition: boolean; +declare const foo: boolean; +declare const bar: boolean; + +// early-exit +(() => { + if (condition) { + do_something(); + } + do_something(); + do_something(); + do_something(); +})(); + +// naming-convention & ordered-imports +class MyClass { + public static my_static_public_property: any; + protected static _my_static_protected_property: any; + private static _my_static_private_property: any; + public my_public_property: any; + protected _my_protected_property: any; + private _my_private_property: any; + constructor() { /* ... */ } + public static my_static_public_method(): void { /* ... */ } + protected static _my_static_protected_method(): void { /* ... */ } + private static _my_static_private_method(): void { /* ... */ } + public my_public_method(): this { return this; } + protected _my_protected_method(): this { return this; } + private _my_private_method(): this { return this; } +} +type MyType = any; +interface MyInterface { my_property: any } +const my_const = 0; +function my_function(param_a: any, _param_b: any): void { /* ... */ } + +// tslint:disable-next-line:no-use-before-declare https://github.com/palantir/tslint/issues/2551 +const {a: _a, ...b_and_c} = {a: 1, b: 2, c: 3}; + +// no-collapsible-if +if (foo && bar) { do_something(); } +if (foo && bar) { + do_something(); +} +if (foo) { + do_something(); +} else if (bar) { + do_something(); +} else { + do_something(); +} +if (foo) { + if (bar) { + do_something(); + } else { + do_something(); + } +} +if (foo) { + if (bar) { + do_something(); + } +} else { + do_something(); +} + +// no-return-undefined +let var_for_return_void; +function return_void(): void { + return void (var_for_return_void = 1); +} + +// prefer-const-enum +const enum MyEnum { + Enum1, + Enum2, +} diff --git a/yarn.lock b/yarn.lock index b1f015e5..fcc92e0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -178,6 +178,13 @@ tslint-config-prettier@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.1.0.tgz#40c026a56e4da27063b3e9bcd71f4f8109fee369" +tslint-consistent-codestyle@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/tslint-consistent-codestyle/-/tslint-consistent-codestyle-1.5.1.tgz#11b6ae6af5a53cb6bd0351d9b6637eabc76d9b7d" + dependencies: + tslib "^1.7.1" + tsutils "^2.5.0" + tslint-eslint-rules@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.1.0.tgz#8fee295c42f4c8078139deb16ee7b4510fd516b7" @@ -205,6 +212,12 @@ tsutils@^1.4.0: version "1.6.0" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.6.0.tgz#1fd7fac2a61369ed99cd3997f0fbb437128850f2" +tsutils@^2.5.0: + version "2.7.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.7.1.tgz#411a0e9466525a2b2869260a55620d7292155e24" + dependencies: + tslib "^1.7.1" + tsutils@^2.5.1: version "2.5.1" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.5.1.tgz#c2001390c79eec1a5ccfa7ac12d599639683e0cf"