├── test ├── rules │ ├── semicolon.ts │ ├── no-multi-spaces.ts │ ├── object-destruct-spacing.ts │ ├── trailing-comma.ts │ ├── space-within-parens.ts │ ├── handle-callback-err.ts │ ├── no-inner-declarations.ts │ ├── ter-arrow-spacing.ts │ ├── curly.ts │ ├── import-spacing.ts │ ├── ter-indent.ts │ └── no-constant-condition.ts ├── tsconfig.json ├── index.js └── rules.out ├── .eslintrc ├── .gitignore ├── .editorconfig ├── .travis.yml ├── LICENSE ├── README.md ├── package.json └── tslint.js /test/rules/semicolon.ts: -------------------------------------------------------------------------------- 1 | export const foo = true; 2 | -------------------------------------------------------------------------------- /test/rules/no-multi-spaces.ts: -------------------------------------------------------------------------------- 1 | export const test = true 2 | -------------------------------------------------------------------------------- /test/rules/object-destruct-spacing.ts: -------------------------------------------------------------------------------- 1 | const fn = ({field}) => ({field}) 2 | -------------------------------------------------------------------------------- /test/rules/trailing-comma.ts: -------------------------------------------------------------------------------- 1 | export const foo = { 2 | a: 1, 3 | b: 2, 4 | } 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "standard", 4 | "prettier" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/rules/space-within-parens.ts: -------------------------------------------------------------------------------- 1 | function test ( a, b ) { 2 | return a < b 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | coverage/ 3 | node_modules/ 4 | npm-debug.log 5 | dist/ 6 | typings/ 7 | -------------------------------------------------------------------------------- /test/rules/handle-callback-err.ts: -------------------------------------------------------------------------------- 1 | export function cb (err) { 2 | console.log('hello world') 3 | } 4 | -------------------------------------------------------------------------------- /test/rules/no-inner-declarations.ts: -------------------------------------------------------------------------------- 1 | export const y: number = 10 2 | 3 | if (y === 0) { 4 | function test () {} 5 | } 6 | -------------------------------------------------------------------------------- /test/rules/ter-arrow-spacing.ts: -------------------------------------------------------------------------------- 1 | export function exec (cb: () => void) { 2 | return cb() 3 | } 4 | 5 | exec(() => null) 6 | -------------------------------------------------------------------------------- /test/rules/curly.ts: -------------------------------------------------------------------------------- 1 | export function test (err) { 2 | if (err) throw err 3 | 4 | if (Math.random() > 0.5) 5 | return false 6 | } 7 | -------------------------------------------------------------------------------- /test/rules/import-spacing.ts: -------------------------------------------------------------------------------- 1 | import{preProcessFile} from 'typescript' 2 | import {findRule} from 'tslint' 3 | 4 | preProcessFile('const x = 10') 5 | -------------------------------------------------------------------------------- /test/rules/ter-indent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a comment. 3 | * 4 | * ``` 5 | * function test () { 6 | * return true 7 | * } 8 | * ``` 9 | */ 10 | export function test () { 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /test/rules/no-constant-condition.ts: -------------------------------------------------------------------------------- 1 | if (true) { 2 | console.log('test') 3 | } 4 | 5 | while (true) { 6 | if (check()) { 7 | break 8 | } 9 | } 10 | 11 | export function check () { 12 | return true 13 | } 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | indent_size = 2 7 | indent_style = space 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | 4 | notifications: 5 | email: 6 | on_success: never 7 | on_failure: change 8 | 9 | node_js: 10 | - "stable" 11 | 12 | after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" 13 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "rules/**/*" 4 | ], 5 | "compilerOptions": { 6 | "target": "esnext", 7 | "lib": ["dom", "es2015"], 8 | "noEmit": true, 9 | "strictNullChecks": true, 10 | "module": "commonjs", 11 | "moduleResolution": "node" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Blake Embrey 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var fs = require("fs"); 2 | var exec = require("child_process").exec; 3 | var path = require("path"); 4 | var test = require("blue-tape"); 5 | 6 | var OUT_FILENAME = path.join(__dirname, "rules.out"); 7 | var TSLINT_BIN = require.resolve("tslint/bin/tslint"); 8 | var TSLINT_CMD = 9 | "node " + 10 | TSLINT_BIN + 11 | ' --config ../tslint.js --project tsconfig.json "rules/**/*.ts"'; 12 | 13 | test("tslint standard", function(t) { 14 | exec(TSLINT_CMD, { cwd: __dirname }, function(err, stdout, stderr) { 15 | t.ok(err); 16 | 17 | const out = relatify(stdout, __dirname).trim(); 18 | 19 | if (process.env.GENERATE_ASSETS) { 20 | return fs.writeFile(OUT_FILENAME, out, function(err) { 21 | t.notOk(err); 22 | t.end(); 23 | }); 24 | } 25 | 26 | fs.readFile(OUT_FILENAME, "utf8", function(err, result) { 27 | t.notOk(err); 28 | 29 | t.equal(out, result); 30 | t.equal(stderr, ""); 31 | 32 | t.end(); 33 | }); 34 | }); 35 | }); 36 | 37 | /** 38 | * Remove all absolute paths when persisting. 39 | */ 40 | function relatify(stdout, dirname) { 41 | let index; 42 | 43 | while ((index = stdout.indexOf(dirname)) > -1) { 44 | stdout = stdout.substr(0, index) + stdout.substr(index + dirname.length); 45 | } 46 | 47 | return stdout; 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TSLint Config Standard 2 | 3 | [![NPM version](https://img.shields.io/npm/v/tslint-config-standard.svg?style=flat)](https://npmjs.org/package/tslint-config-standard) 4 | [![NPM downloads](https://img.shields.io/npm/dm/tslint-config-standard.svg?style=flat)](https://npmjs.org/package/tslint-config-standard) 5 | [![Build status](https://img.shields.io/travis/blakeembrey/tslint-config-standard.svg?style=flat)](https://travis-ci.org/blakeembrey/tslint-config-standard) 6 | 7 | > A [TSLint config](https://palantir.github.io/tslint/usage/tslint-json/) for [JavaScript Standard Style](http://standardjs.com/) 8 | 9 | ## Installation 10 | 11 | ```sh 12 | npm install tslint-config-standard --save-dev 13 | ``` 14 | 15 | ## Usage 16 | 17 | In `tslint.json`: 18 | 19 | ```json 20 | { 21 | "extends": "tslint-config-standard" 22 | } 23 | ``` 24 | 25 | **P.S.** Some TSLint rules require the use of [`--project`](https://palantir.github.io/tslint/usage/cli/#cli-usage) to run. 26 | 27 | ### Rules 28 | 29 | - [TSLint](https://www.npmjs.com/package/tslint) 30 | - [TSLint ESLint Rules](https://www.npmjs.com/package/tslint-eslint-rules) 31 | 32 | ### Help 33 | 34 | Many [**TSLint ESLint Rules**](https://github.com/buzinas/tslint-eslint-rules#rules-copied-from-the-eslint-website) are incomplete and can use your help! 35 | 36 | ## License 37 | 38 | Apache 2.0 39 | -------------------------------------------------------------------------------- /test/rules.out: -------------------------------------------------------------------------------- 1 | ERROR: /rules/curly.ts[4, 3]: if statements must be braced 2 | ERROR: /rules/handle-callback-err.ts[1, 21]: Expected error to be handled 3 | ERROR: /rules/import-spacing.ts[1, 7]: missing whitespace 4 | ERROR: /rules/import-spacing.ts[1, 7]: A space is required after '{' 5 | ERROR: /rules/import-spacing.ts[1, 22]: A space is required before '}' 6 | ERROR: /rules/import-spacing.ts[2, 8]: A space is required after '{' 7 | ERROR: /rules/import-spacing.ts[2, 17]: A space is required before '}' 8 | ERROR: /rules/no-constant-condition.ts[1, 5]: unexpected constant condition 9 | ERROR: /rules/no-inner-declarations.ts[4, 3]: move function declaration to program root 10 | ERROR: /rules/no-inner-declarations.ts[4, 20]: block is empty 11 | ERROR: /rules/no-multi-spaces.ts[1, 22]: Multiple spaces found before 'true'. 12 | ERROR: /rules/object-destruct-spacing.ts[1, 13]: A space is required after '{' 13 | ERROR: /rules/object-destruct-spacing.ts[1, 19]: A space is required before '}' 14 | ERROR: /rules/object-destruct-spacing.ts[1, 26]: A space is required after '{' 15 | ERROR: /rules/object-destruct-spacing.ts[1, 32]: A space is required before '}' 16 | ERROR: /rules/semicolon.ts[1, 24]: Unnecessary semicolon 17 | ERROR: /rules/space-within-parens.ts[1, 16]: Whitespace within parentheses is not allowed 18 | ERROR: /rules/space-within-parens.ts[1, 21]: Whitespace within parentheses is not allowed 19 | ERROR: /rules/ter-arrow-spacing.ts[5, 10]: Multiple spaces found before '=>'. 20 | ERROR: /rules/ter-indent.ts[11, 1]: Expected indentation of 2 spaces but found 3. 21 | ERROR: /rules/trailing-comma.ts[3, 7]: Unnecessary trailing comma -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tslint-config-standard", 3 | "version": "9.0.0", 4 | "description": "A TSLint config for JavaScript Standard Style", 5 | "main": "tslint.js", 6 | "files": [ 7 | "tslint.js", 8 | "README.md", 9 | "LICENSE" 10 | ], 11 | "scripts": { 12 | "lint": "eslint \"*.js\" \"test/*.js\"", 13 | "prettier": "prettier --write", 14 | "format": "npm run prettier -- \"{.,test}/*.{js,md,yml,yaml}\"", 15 | "test:gen": "GENERATE_ASSETS=true blue-tape test/index.js", 16 | "test:spec": "blue-tape test/index.js | tap-spec", 17 | "test": "npm run lint && npm run test:spec" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "git://github.com/blakeembrey/tslint-config-standard.git" 22 | }, 23 | "keywords": [ 24 | "tslint", 25 | "config", 26 | "standard", 27 | "standardjs", 28 | "typescript", 29 | "ts" 30 | ], 31 | "author": { 32 | "name": "Blake Embrey", 33 | "email": "hello@blakeembrey.com", 34 | "url": "http://blakeembrey.me" 35 | }, 36 | "license": "Apache-2.0", 37 | "bugs": { 38 | "url": "https://github.com/blakeembrey/tslint-config-standard/issues" 39 | }, 40 | "homepage": "https://github.com/blakeembrey/tslint-config-standard", 41 | "husky": { 42 | "hooks": { 43 | "pre-commit": "lint-staged" 44 | } 45 | }, 46 | "lint-staged": { 47 | "*.{js,jsx,ts,tsx,json,css,md,yml,yaml}": [ 48 | "npm run prettier", 49 | "git add" 50 | ] 51 | }, 52 | "publishConfig": { 53 | "access": "public" 54 | }, 55 | "devDependencies": { 56 | "@types/node": "^12.12.5", 57 | "blue-tape": "^1.0.0", 58 | "eslint": "^6.6.0", 59 | "eslint-config-prettier": "^6.5.0", 60 | "eslint-config-standard": "^14.1.0", 61 | "husky": "^3.0.9", 62 | "lint-staged": "^9.4.2", 63 | "prettier": "^1.18.2", 64 | "standard": "^14.3.1", 65 | "tap-spec": "^5.0.0", 66 | "tslint": "^5.8.0", 67 | "typescript": "^3.6.4" 68 | }, 69 | "dependencies": { 70 | "tslint-eslint-rules": "^5.3.1" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tslint.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["tslint-eslint-rules"], 3 | rules: { 4 | // TSLint rules. 5 | "no-internal-module": true, 6 | "typedef-whitespace": [ 7 | true, 8 | { 9 | "call-signature": "nospace", 10 | "index-signature": "nospace", 11 | parameter: "nospace", 12 | "property-declaration": "nospace", 13 | "variable-declaration": "nospace" 14 | }, 15 | { 16 | "call-signature": "onespace", 17 | "index-signature": "onespace", 18 | parameter: "onespace", 19 | "property-declaration": "onespace", 20 | "variable-declaration": "onespace" 21 | } 22 | ], 23 | "await-promise": true, 24 | curly: [true, "ignore-same-line"], 25 | deprecation: true, 26 | "label-position": true, 27 | "no-arg": true, 28 | "no-conditional-assignment": true, 29 | "no-duplicate-imports": true, 30 | "no-duplicate-variable": true, 31 | "no-empty": true, 32 | "no-eval": true, 33 | "no-reference-import": true, 34 | "no-return-await": true, 35 | "no-switch-case-fall-through": true, 36 | "no-unused-expression": [ 37 | true, 38 | "allow-fast-null-checks", 39 | "allow-tagged-template" 40 | ], 41 | "no-var-keyword": true, 42 | radix: true, 43 | "space-within-parens": [true, 0], 44 | "triple-equals": [true, "allow-null-check"], 45 | "use-isnan": true, 46 | eofline: true, 47 | "ter-indent": [ 48 | true, 49 | 2, 50 | { 51 | SwitchCase: 1 52 | } 53 | ], 54 | "no-trailing-whitespace": true, 55 | "trailing-comma": [ 56 | true, 57 | { 58 | multiline: "never", 59 | singleline: "never" 60 | } 61 | ], 62 | "class-name": true, 63 | "comment-format": [true, "check-space"], 64 | "jsdoc-format": true, 65 | "new-parens": true, 66 | "no-angle-bracket-type-assertion": true, 67 | "no-consecutive-blank-lines": true, 68 | "no-floating-promises": true, 69 | "no-misused-new": true, 70 | "no-string-throw": true, 71 | "no-unnecessary-qualifier": true, 72 | "no-unnecessary-type-assertion": true, 73 | "one-line": [ 74 | true, 75 | "check-catch", 76 | "check-finally", 77 | "check-else", 78 | "check-open-brace", 79 | "check-whitespace" 80 | ], 81 | "one-variable-per-declaration": true, 82 | quotemark: [true, "single", "avoid-escape", "jsx-single"], 83 | semicolon: [true, "never"], 84 | "strict-type-predicates": true, 85 | "space-before-function-paren": [true, "always"], 86 | "unified-signatures": true, 87 | "variable-name": [ 88 | true, 89 | "ban-keywords", 90 | "check-format", 91 | "allow-leading-underscore", 92 | "allow-pascal-case" 93 | ], 94 | whitespace: [ 95 | true, 96 | "check-branch", 97 | "check-decl", 98 | "check-operator", 99 | // 'check-module', 100 | "check-rest-spread", 101 | "check-type", 102 | "check-typecast", 103 | "check-type-operator", 104 | "check-preblock" 105 | ], 106 | // TSLint ESLint rules. 107 | "no-constant-condition": [ 108 | true, 109 | { 110 | checkLoops: false 111 | } 112 | ], 113 | "no-control-regex": true, 114 | "no-duplicate-case": true, 115 | "no-empty-character-class": true, 116 | "no-ex-assign": true, 117 | "no-extra-boolean-cast": true, 118 | "no-inner-declarations": [true, "functions"], 119 | "no-invalid-regexp": true, 120 | "ter-no-irregular-whitespace": true, 121 | "no-regex-spaces": true, 122 | "ter-no-sparse-arrays": true, 123 | "ter-func-call-spacing": [true, "never"], 124 | "no-unexpected-multiline": true, 125 | "valid-typeof": true, 126 | "ter-arrow-spacing": [ 127 | true, 128 | { 129 | before: true, 130 | after: true 131 | } 132 | ], 133 | "no-multi-spaces": true, 134 | "handle-callback-err": [true, "^(err|error)$"], 135 | "block-spacing": [true, "always"], 136 | "brace-style": [ 137 | true, 138 | "1tbs", 139 | { 140 | allowSingleLine: true 141 | } 142 | ], 143 | "object-curly-spacing": [true, "always"] 144 | }, 145 | jsRules: true 146 | }; 147 | --------------------------------------------------------------------------------