Skip to content

codenamekt/tslint-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

tslint-json

A sane tslint style.

These represent sane defaults for a typescript project (file an issue if found insane). The aim of this project is to keep a solid working style for each tslint version, tagged to keep consistancy.

Rules

See tslint rules for additional information.

array-type

    "array-type": [true, "generic"]

Requires using either T[] or Array for arrays.

All objects/classes to be referenced capcase.

Example

    public test(testSteps: Array<Array<string>>, testName: string): void {}

arrow-parens

   "arrow-parens": [true]

Requires parentheses around the parameters of arrow function definitions.

class-name: Boolean

   "class-name": true

Enforce PascalCased class and interface names. Makes it easy to differentitate classes from regular variables at a glance.

cyclomatic-complexity: Boolean | Array

    "cyclomatic-complexity": [true, 3]

Complexity based on statements and expressions such as * catch * if and ? : * || and && due to short-circuit evaluation * for, for in and for of loops * while and do while loops. 3 is sane. 4, insane.

comment-format: Array

    "comment-format": [true, "check-space"]

Enforce formatting rules for single-line comments.

eofline: Boolean

    "eofline": true

Ensure the file ends with a newline.

indent: Array

    "indent": [true, "spaces"]

Enforce indentation with spaces.

jsdoc-format: Boolean

    "jsdoc-format": true

Enforce basic format rules for JSDoc comments.

max-classes-per-file: Array

    "max-classes-per-file": [true, 1]

Ensures that files have a single responsibility so that that classes each exist in their own files and 1 per file keeps everyone sane. Should also name the file the [classname].ts.

max-file-line-count: Array

    "max-file-line-count": [true, 100]

Ensure a file stays under a certain line count. Most people don't like scrolling more than 300.

no-default-export: Booleanhighlighter symantec

    "no-default-export": true

Be original, name your import something other than default.

no-duplicate-variable: Array

    "no-duplicate-variable": [true, 1]

There’s no good reason to have a duplicate variable declaration.

no-parameter-properties: Array

    "no-parameter-properties": true

More verbose and explicit but easier to understand. Example

no-eval: Boolean

    "no-eval": true

Eval is unsafe. Try .call() or some other method to achieve your goals.

no-internal-module: Boolean

    "no-internal-module": true

Use the namespace keyword and not module.

no-trailing-whitespace: Array

    "no-trailing-whitespace": true

No trailing whitespace.

no-unsafe-finally: Boolean

    "no-unsafe-finally": true

Disallows control flow statements, such as return, continue, break and throws in finally blocks.

no-var-keyword: Boolean

    "no-var-keyword": true

Use let or const instead of var.

object-literal-key-quotes: Array

    "object-literal-key-quotes": [true, "always"]

Property names should always be quoted.

object-literal-shorthand: Boolean

    "object-literal-shorthand": true

Enforce use of ES6 object literal shorthand when possible.

object-literal-sort-keys: Boolean

    "object-literal-sort-keys": true

Require keys in object literals to be sorted alphabetically.

one-line: Array

    "one-line": [
        true,
        "check-open-brace",
        "check-whitespace"
    ]

Require the open brace and whitespace to be on the same line as the expression preceding them.

ordered-imports: Array

    "ordered-imports": [
        true,
        {
            "import-sources-order": "lowercase-last",
            "named-imports-order": "lowercase-first"
        }
    ]

Require that import statements be alphabetized.

one-variable-per-declaration: Boolean

    "one-variable-per-declaration": [true, "ignore-for-loop"]

No multiline declaration unless in a for loop.

quotemark: Array

    "one-variable-per-declaration": [true, "double"]

Require double quotes for string literals.

semicolon: Array

    "semicolon": [
        true,
        "always"
    ]

Enforce semicolons at the end of every statement including bound class methods and interfaces.

trailing-comma: Array

    "trailing-comma": [
        false,
        {
            "multiline": "never",
            "singleline": "never"
        }
    ]

Disallow trailing commas in array and object literals, destructuring assignments, function and tuple typings, named imports and function parameters.

triple-equals: Boolean

    "triple-equals": true

Requires === and !==, no exceptions.

typedef-whitespace: Array

    "typedef-whitespace": [
        true,
        {
            "call-signature": "nospace",
            "index-signature": "nospace",
            "parameter": "nospace",
            "property-declaration": "nospace",
            "variable-declaration": "nospace"
        }
    ]

No space is required before the colon in a type specifier.

variable-name: Array

    "variable-name": [
        true,
        "check-format",
        "allow-leading-underscore",
        "allow-trailing-underscore",
        "allow-pascal-case",
        "ban-keywords"
    ]

Checks variable names for various errors.

  • "check-format": allow only camelCased or UPPER_CASED variable names
    • "allow-leading-underscore": allow underscores at the beginning (only has an effect if “check-format” specified)
    • "allow-trailing-underscore": allow underscores at the end. (only has an effect if “check-format” specified)
    • "allow-pascal-case": allow PascalCase in addtion to camelCase.
  • "ban-keywords": Do not allow the use of certain TypeScript keywords (any, Number, number, String, string, Boolean, boolean, undefined) as variable or parameter names.

whitespace: Array

    "whitespace": [
        true,
        "check-branch",
        "check-decl",
        "check-operator",
        "check-module",
        "check-separator",
        "check-type",
        "check-typecast"
    ]

Enforce whitespace style conventions.

  • "check-branch" check branching statements (if/else/for/while) are followed by whitespace.
  • "check-decl" check that variable declarations have whitespace around the equals token.
  • "check-operator" check for whitespace around operator tokens.
  • "check-module" check for whitespace in import & export statements.
  • "check-separator" check for whitespace after separator tokens (,/;).
  • "check-type" check for whitespace before a variable type specification.
  • "check-typecast" check for whitespace between a typecast and its target.
  • "check-preblock" check for whitespace before the opening brace of a block