UNPKG

6.19 kBMarkdownView Raw
1# FSCodeStyle
2
3This repository contains a set of linting rules for TypeScript React projects. These are the same
4rules used by Flagship. If you're developing a project using Flagship, we recommend enforcing these rules.
5
6## Pre-Requisites
7
8Your project must have the following:
9
10* A [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file indicating
11 the root files and base directories for the TypeScript compiler
12
13## Usage
14
151. Add a dependency in your project `yarn add @brandingbrand/fscodestyle`
162. Add a lint script to your package.json `"lint": "fscodestyle"`
17
18We recommend you set this up as a precommit hook using [Husky](https://github.com/typicode/husky)
19
20## Linting
21
22The linter uses [tslint](https://github.com/palantir/tslint). In addition, the following rule
23extensions have been added:
24
25* [tslint-eslint-rules](https://www.npmjs.com/package/tslint-eslint-rules) - adds missing eslint
26 rules to tslint
27* [tslint-react](https://github.com/palantir/tslint-react) - adds React rules to tslint
28
29### Highlights
30
31* Indentation: 2 spaces
32* Maximum line length: 100 characters
33* No more than two consecutive empty lines
34* No trailing whitespace at the end of lines
35* Use `let` and `const` instead of `var`
36* Use single quotes for string literals
37* Use `===` and `!==` instead of `==` and `!=`
38* TypeScript: Use `const x: T = { ... };` notation instead of `const x = { ...} as T;`
39* TypeScript: Use interfaces over type literals
40
41### Rules in Depth
42
43|Name|Description|Package|
44|----|-----------|-------|
45|arrow-parens|Arrow functions with multiple arguments must use parentheses; single arguments must not.|tslint|
46|no-unnecessary-type-assertion|Warn if a type assertion is not necessary for an expression|tslint|
47|typedef|Requires type definitions to exist. Checks function return types, parameters, and member variable declarations.|tslint|
48|typedef-whitespace|Requires no space to exist to the left of the colon in a type definition|tslint|
49|await-promise|Warns if an awaited value is not a promise.|tslint|
50|no-floating-promises|Requires promises returned by functions to be handled appropriately.|tslint|
51|no-inferred-empty-object-type|Disallow type inference of {} (empty object type) at function and constructor call sites|tslint|
52|no-unbound-method|Disallow use of an unbound class method as a callback|tslint|
53|no-unused-variable|Disallows unused imports, variables, functions, and private class members|tslint|
54|use-default-type-parameter|Warns if an explicitly specified type argument is the default for that type parameter.|tslint|
55|no-mergeable-namespace|Disallows mergeable namespaces in the same file.|tslint|
56|array-type|Enforces use of `T[]` for array types|tslint|
57|no-boolean-literal-compare|Warns on comparison to a boolean literal, as in `x === true`.|tslint|
58|type-literal-delimiter|Checks that type literal members are separated by semicolons. Enforces a trailing semicolon for multiline type literals.|tslint|
59|trailing-comma|Disallow trailing commas|tslint|
60|no-constant-condition|Disallow use of constant expressions in conditions|tslint|
61|cyclomatic-complexity|Allow maximum cyclomatic complexity of 10|tslint|
62|switch-default|Require `default` case in `switch` statements|tslint|
63|triple-equals|Require use of `===` and `!==`|tslint|
64|guard-for-in|Make sure `for-in` loops have an `if` statement|tslint|
65|no-switch-case-fall-through|Disallow fallthrough of `case` statements|tslint|
66|no-magic-numbers|Disallow use of magic numbers except -1, 0, 1, 2, 100, 1000|tslint|
67|no-duplicate-variable|Disallow declaring the same variable more than once|tslint|
68|no-use-before-declare|Disallow use of variables before they are defined|tslint|
69|variable-name|Require camel-cace names|tslint|
70|linebreak-style|Enforce Unix-style linebreaks|tslint|
71|no-consecutive-blank-lines|Disallow more than two consecutive blank lines|tslint|
72|no-trailing-spaces|Disallow trailing whitespace at end of lines|tslint|
73|one-variable-per-declaration|Require no more than one variable declaration per function|tslint|
74|object-literal-key-quotes|Require quotes around object literal property names as needed|tslint|
75|quotemark|Require single quotes for string literal|tslint|
76|semicolon|Require semicolons|tslint|
77|comment-format|Require that single-line comments begin with a space after the `//`|tslint|
78|no-control-regex|Disallow control characters in regular expressions (recommended)|tslint-eslint-rules|
79|no-duplicate-case|Disallow duplicate case labels in a switch statement|tslint-eslint-rules|
80|no-empty-character-class|Disallow the use of empty character classes in regular expressions|tslint-eslint-rules|
81|no-ex-assign|Disallow assigning to the expection in a `catch` block|tslint-eslint-rules|
82|no-extra-semi|Disallow unnecessary semicolons|tslint-eslint-rules|
83|no-inner-declarations|Disallow function declarations in nested blocks|tslint-eslint-rules|
84|no-invalid-regexp|Disallow invalid regular expression strings in the `RegExp` constructor|tslint-eslint-rules|
85|ter-no-irregular-whitespace|Disallow irregular whitespace|tslint-eslint-rules|
86|no-regex-spaces|Disallow multiple spaces in a regular expression literal|tslint-eslint-rules|
87|no-unexpected-multiline|Disallow code that looks like two expressions but is actually one|tslint-eslint-rules|
88|valid-jsdoc|Enforce valid JSDoc comments|tslint-eslint-rules|
89|valid-typeof|Ensure that the results of typeof are compared against a valid string|tslint-eslint-rules|
90|no-multi-spaces|Disallow use of multiple spaces|tslint-eslint-rules|
91|handle-callback-err|Enforce error handling in callbacks|tslint-eslint-rules|
92|array-bracket-spacing|Disallow after and before array brackets|tslint-eslint-rules|
93|block-spacing|Require spacies inside of single line blocks|tslint-eslint-rules|
94|brace-style|Require "one true brace style" in which the opening brace of a block is placed on the same line as its statement or declaration|tslint-eslint-rules|
95|ter-func-call-spacing|Require spacing between function identifiers and their incovations|tslint-eslint-rules|
96|ter-indent|Enforce consistent indentation: 2 spaces|tslint-eslint-rules|
97|ter-max-len|Enforce max line length of 100|tslint-eslint-rules|