ts-configdeprecated

An opinionated TSLint configuration preset. Works best together with strict TypeScript settings and Prettier.

Usage no npm install needed!

<script type="module">
  import tsConfig from 'https://cdn.skypack.dev/ts-config';
</script>

README

ts-config

Package Version Build Status

An opinionated TSLint configuration preset. Works best together with strict TypeScript settings and Prettier.

Getting started

First, install ts-config as a dev dependency:

# Install using Yarn
yarn add -D ts-config tslint typescript
# or install using npm
npm install -D ts-config tslint typescript

Then use the CLI to create a TSLint configuration file that extends this configuration preset:

npx ts-config init-tslint

Optional: Use the CLI to create a TypeScript configuration file with strict settings:

# Create a TypeScript configuration
npx ts-config init-typescript
# or create a TypeScript configuration for a React project
npx ts-config init-typescript --react

Now you can run TSLint as follows (assuming that TypeScript and Prettier are configured accordingly):

# Lint your TS sources
npx tslint --config tslint.json --project . '**/*.{ts,tsx}'
# and lint your JS sources
npx tslint --config tslint.json '**/*.{js,jsx}'

CLI commands

init-tslint

$ npx ts-config init-tslint help

Creates a TSLint configuration file that extends this configuration preset.

USAGE
  $ ts-config init-tslint

OPTIONS
  -c, --config=config  [default: tslint.json]
  -f, --force          overwrite an existing configuration file
  -h, --help           show CLI help

EXAMPLES
  $ ts-config init-tslint
  $ ts-config init-tslint --config='tslint.build.json' --force

init-typescript

$ npx ts-config init-typescript help

Creates a TypeScript configuration file with strict settings.

USAGE
  $ ts-config init-typescript

OPTIONS
  -c, --config=config  [default: tsconfig.json]
  -f, --force          overwrite an existing configuration file
  -h, --help           show CLI help
  -r, --react          add React-specific settings

EXAMPLES
  $ ts-config init-typescript
  $ ts-config init-typescript --config='tsconfig.build.json' --force --react

Configuration preset

This dynamically generated configuration preset is compatible to TSLint in version ^5.10.0. It is based on the built-in configuration preset tslint:all:

tslint:all turns on all rules to their strictest settings. This will use type checking, so it must be combined with the --project option. (Exceptions include rules such as "ban", "import-blacklist", and "file-header", which have no sensible defaults, and deprecated rules.)

It is assumed that TypeScript is configured with strict settings. Also, it is assumed that Prettier is used for formatting your sources.

The deviations from the configuration preset tslint:all@5.18.0 are documented below:

TypeScript and JavaScript rule overrides

align

  • Unnecessary because of Prettier.
{
-  align: {
-    options: [
-      "parameters"
-      "arguments"
-      "statements"
-      "elements"
-      "members"
-    ]
-  }
+  align: false
 }

arrow-parens

  • Unnecessary because of Prettier.
{
-  arrow-parens: true
+  arrow-parens: false
 }

comment-format

{
   comment-format: {
     options: [
       "check-space"
-      "check-uppercase"
     ]
   }
 }

completed-docs

{
-  completed-docs: true
+  completed-docs: false
 }

file-name-casing

{
   file-name-casing: {
-    options: "camel-case"
+    options: [
+      "kebab-case"
+    ]
   }
 }

indent

  • Unnecessary because of Prettier.
{
-  indent: {
-    options: [
-      "spaces"
-    ]
-  }
+  indent: false
 }

max-classes-per-file

{
-  max-classes-per-file: {
-    options: 1
-  }
+  max-classes-per-file: false
 }

max-file-line-count

{
-  max-file-line-count: {
-    options: 1000
-  }
+  max-file-line-count: false
 }

max-line-length

  • Unnecessary because of Prettier.
{
-  max-line-length: {
-    options: {
-      limit: 120
-    }
-  }
+  max-line-length: false
 }

member-ordering

{
   member-ordering: {
     options: {
-      alphabetize: true
     }
   }
 }

newline-per-chained-call

  • Unnecessary because of Prettier.
{
-  newline-per-chained-call: true
+  newline-per-chained-call: false
 }

no-console

{
-  no-console: true
+  no-console: false
 }

no-default-import

{
-  no-default-import: true
+  no-default-import: false
 }

no-empty

{
-  no-empty: true
+  no-empty: {
+    options: [
+      "allow-empty-catch"
+    ]
+  }
 }

no-import-side-effect

{
-  no-import-side-effect: true
+  no-import-side-effect: false
 }

no-magic-numbers

{
-  no-magic-numbers: true
+  no-magic-numbers: false
 }

no-null-keyword

{
-  no-null-keyword: true
+  no-null-keyword: false
 }

no-submodule-imports

{
-  no-submodule-imports: true
+  no-submodule-imports: false
 }

no-this-assignment

{
-  no-this-assignment: true
+  no-this-assignment: {
+    options: {
+      allow-destructuring: true
+    }
+  }
 }

no-unnecessary-callback-wrapper

{
-  no-unnecessary-callback-wrapper: true
+  no-unnecessary-callback-wrapper: false
 }

no-unnecessary-class

{
   no-unnecessary-class: {
     options: [
+      "allow-constructor-only"
       "allow-empty-class"
+      "allow-static-only"
     ]
   }
 }

object-literal-key-quotes

  • Unnecessary because of Prettier.
{
-  object-literal-key-quotes: {
-    options: "consistent-as-needed"
-  }
+  object-literal-key-quotes: false
 }

object-literal-sort-keys

{
-  object-literal-sort-keys: true
+  object-literal-sort-keys: false
 }

only-arrow-functions

{
-  only-arrow-functions: true
+  only-arrow-functions: {
+    options: [
+      "allow-declarations"
+    ]
+  }
 }

ordered-imports

{
   ordered-imports: {
     options: {
-      grouped-imports: true
-      module-source-path: "full"
-      import-sources-order: "case-insensitive"
+      import-sources-order: "lowercase-last"
-      named-imports-order: "case-insensitive"
+      named-imports-order: "lowercase-last"
     }
   }
 }

prefer-function-over-method

{
-  prefer-function-over-method: true
+  prefer-function-over-method: false
 }

prefer-template

{
-  prefer-template: true
+  prefer-template: {
+    options: [
+      "allow-single-concat"
+    ]
+  }
 }

quotemark

  • Unnecessary because of Prettier.
{
-  quotemark: {
-    options: [
-      "double"
-      "avoid-escape"
-      "avoid-template"
-    ]
-  }
+  quotemark: false
 }

semicolon

  • Unnecessary because of Prettier.
{
-  semicolon: {
-    options: [
-      "always"
-    ]
-  }
+  semicolon: false
 }

switch-default

  • TypeScript-only: Unnecessary because of the TypeScript setting --noImplicitReturns.
{
-  switch-default: true
+  switch-default: false
 }

trailing-comma

  • Unnecessary because of Prettier.
{
-  trailing-comma: {
-    options: {
-      esSpecCompliant: true
-      multiline: "always"
-      singleline: "never"
-    }
-  }
+  trailing-comma: false
 }

triple-equals

{
-  triple-equals: true
+  triple-equals: {
+    options: [
+      "allow-null-check"
+    ]
+  }
 }

variable-name

{
   variable-name: {
     options: [
       "ban-keywords"
       "check-format"
-      "require-const-for-all-caps"
+      "allow-pascal-case"
+      "allow-leading-underscore"
     ]
   }
 }

whitespace

  • Unnecessary because of Prettier.
{
-  whitespace: {
-    options: [
-      "check-branch"
-      "check-decl"
-      "check-operator"
-      "check-module"
-      "check-separator"
-      "check-type"
-      "check-typecast"
-      "check-preblock"
-      "check-type-operator"
-      "check-rest-spread"
-    ]
-  }
+  whitespace: false
 }

TypeScript-only rule overrides

array-type

{
   array-type: {
-    options: "array-simple"
+    options: [
+      "array"
+    ]
   }
 }

ban-ts-ignore

{
-  ban-ts-ignore: true
+  ban-ts-ignore: false
 }

interface-name

{
-  interface-name: true
+  interface-name: {
+    options: [
+      "never-prefix"
+    ]
+  }
 }

match-default-export-name

{
-  match-default-export-name: true
+  match-default-export-name: false
 }

no-empty-interface

{
-  no-empty-interface: true
+  no-empty-interface: false
 }

no-inferrable-types

{
   no-inferrable-types: {
     options: [
       "ignore-params"
+      "ignore-properties"
     ]
   }
 }

no-object-literal-type-assertion

{
-  no-object-literal-type-assertion: true
+  no-object-literal-type-assertion: false
 }

no-parameter-properties

{
-  no-parameter-properties: true
+  no-parameter-properties: false
 }

no-unbound-method

{
-  no-unbound-method: true
+  no-unbound-method: false
 }

no-unsafe-any

{
-  no-unsafe-any: true
+  no-unsafe-any: false
 }

no-use-before-declare

{
-  no-use-before-declare: true
+  no-use-before-declare: false
 }

no-void-expression

{
-  no-void-expression: true
+  no-void-expression: {
+    options: [
+      "ignore-arrow-function-shorthand"
+    ]
+  }
 }

return-undefined

{
-  return-undefined: true
+  return-undefined: false
 }

strict-boolean-expressions

{
-  strict-boolean-expressions: true
+  strict-boolean-expressions: false
 }

strict-comparisons

{
-  strict-comparisons: true
+  strict-comparisons: {
+    options: {
+      allow-object-equal-comparison: true
+    }
+  }
 }

strict-type-predicates

{
-  strict-type-predicates: true
+  strict-type-predicates: false
 }

typedef

{
   typedef: {
     options: [
       "call-signature"
-      "arrow-call-signature"
       "parameter"
-      "arrow-parameter"
       "property-declaration"
-      "variable-declaration"
-      "member-variable-declaration"
     ]
   }
 }

JavaScript-only rule overrides

no-require-imports

{
-  no-require-imports: true
+  no-require-imports: false
 }

switch-default

  • TypeScript-only: Unnecessary because of the TypeScript setting --noImplicitReturns.
{
-  switch-default: false
+  switch-default: true
 }

Copyright (c) 2016-present, Clemens Akens. Released under the terms of the MIT License.