|
| 1 | +/** |
| 2 | + * Js-coding-standards |
| 3 | + * |
| 4 | + * @author Robert Rossmann <rr.rossmann@me.com> |
| 5 | + * @copyright 2018 STRV |
| 6 | + * @license http://choosealicense.com/licenses/bsd-3-clause BSD-3-Clause License |
| 7 | + */ |
| 8 | + |
| 9 | +'use strict' |
| 10 | + |
| 11 | +module.exports = { |
| 12 | + |
| 13 | + plugins: [ |
| 14 | + 'typescript', |
| 15 | + ], |
| 16 | + |
| 17 | + parserOptions: { |
| 18 | + ecmaVersion: 2018, |
| 19 | + sourceType: 'module', |
| 20 | + }, |
| 21 | + |
| 22 | + env: { |
| 23 | + es6: true, |
| 24 | + }, |
| 25 | + |
| 26 | + rules: { |
| 27 | + // TS code is mostly self-documented and having JSDoc directives for everything is redundant |
| 28 | + // when you can easily infer return values and argument types from the code itself. |
| 29 | + 'valid-jsdoc': 'off', |
| 30 | + |
| 31 | + // Disabled because it generates false positives with interface declarations and TypeScript |
| 32 | + // blows up anyway during compilation when it encouters an undefined variable. |
| 33 | + 'no-undef': 'off', |
| 34 | + |
| 35 | + // Require that member overloads be consecutive |
| 36 | + // Grouping overloaded members together can improve readability of the code. |
| 37 | + 'typescript/adjacent-overload-signatures': 'warn', |
| 38 | + |
| 39 | + // Require PascalCased class and interface names |
| 40 | + // This rule aims to make it easy to differentiate classes from regular variables at a glance. |
| 41 | + 'typescript/class-name-casing': 'warn', |
| 42 | + |
| 43 | + // Require explicit return types on functions and class methods |
| 44 | + // Explicit types for function return values makes it clear to any calling code what type is |
| 45 | + // returned. This ensures that the return value is assigned to a variable of the correct type; |
| 46 | + // or in the case where there is no return value, that the calling code doesn't try to use the |
| 47 | + // undefined value when it shouldn't. |
| 48 | + 'typescript/explicit-function-return-type': ['warn', { |
| 49 | + allowExpressions: true, |
| 50 | + }], |
| 51 | + |
| 52 | + // Require explicit accessibility modifiers on class properties and methods |
| 53 | + // This rule aims to make code more readable and explicit about who can use which properties. |
| 54 | + 'typescript/explicit-member-accessibility': 'warn', |
| 55 | + |
| 56 | + // Require that interface names be prefixed with I |
| 57 | + // It can be hard to differentiate between classes and interfaces. Prefixing interfaces with "I" |
| 58 | + // can help telling them apart at a glance. |
| 59 | + 'typescript/interface-name-prefix': ['warn', 'always'], |
| 60 | + |
| 61 | + // Require a specific member delimiter style for interfaces and type literals |
| 62 | + // This rule aims to standardise the way interface and type literal members are delimited. |
| 63 | + 'typescript/member-delimiter-style': ['warn', { |
| 64 | + delimiter: 'none', |
| 65 | + }], |
| 66 | + |
| 67 | + // Require a consistent member declaration order |
| 68 | + // A consistent ordering of fields, methods and constructors can make interfaces, type literals, |
| 69 | + // classes and class expressions easier to read, navigate and edit. |
| 70 | + 'typescript/member-ordering': 'warn', |
| 71 | + |
| 72 | + // Enforces the use of `as Type` assertions instead of `<Type>` assertions |
| 73 | + // This rule aims to standardise the use of type assertion style across the codebase. |
| 74 | + 'typescript/no-angle-bracket-type-assertion': 'warn', |
| 75 | + |
| 76 | + // Disallow generic Array constructors |
| 77 | + // Use of the Array constructor to construct a new array is generally discouraged in favor of |
| 78 | + // array literal notation because of the single-argument pitfall and because the Array global |
| 79 | + // may be redefined. |
| 80 | + 'typescript/no-array-constructor': 'error', |
| 81 | + |
| 82 | + // Disallow the declaration of empty interfaces |
| 83 | + // An empty interface is equivalent to its supertype. If the interface does not implement a |
| 84 | + // supertype, then the interface is equivalent to an empty object ({}). In both cases it can be |
| 85 | + // omitted. |
| 86 | + 'typescript/no-empty-interface': 'warn', |
| 87 | + |
| 88 | + // Disallows explicit type declarations for variables or parameters initialized to a number, |
| 89 | + // string, or boolean |
| 90 | + // This rule disallows explicit type declarations on parameters, variables and properties where |
| 91 | + // the type can be easily inferred from its value. |
| 92 | + 'typescript/no-explicit-any': 'warn', |
| 93 | + |
| 94 | + |
| 95 | + // Disallow the use of custom TypeScript modules and namespaces |
| 96 | + // Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered |
| 97 | + // outdated ways to organize TypeScript code. ES2015 module syntax is now preferred |
| 98 | + // (import/export). |
| 99 | + 'typescript/no-namespace': 'error', |
| 100 | + |
| 101 | + // Disallow non-null assertions using the ! postfix operator |
| 102 | + // Using non-null assertions cancels the benefits of the strict null-checking mode. |
| 103 | + 'typescript/no-non-null-assertion': 'warn', |
| 104 | + |
| 105 | + // Disallow the use of parameter properties in class constructors |
| 106 | + // This rule disallows the use of parameter properties in constructors, forcing the user to |
| 107 | + // explicitly declare all properties in the class. |
| 108 | + 'typescript/no-parameter-properties': 'warn', |
| 109 | + |
| 110 | + // Disallow /// <reference path="" /> comments |
| 111 | + // Triple-slash reference directive comments should not be used anymore. Use import instead. |
| 112 | + 'typescript/no-triple-slash-reference': 'error', |
| 113 | + |
| 114 | + // Prevent TypeScript-specific constructs from being erroneously flagged as unused |
| 115 | + // This rule only has an effect when the no-unused-vars core rule is enabled. It ensures that |
| 116 | + // TypeScript-specific constructs, such as implemented interfaces, are not erroneously flagged |
| 117 | + // as unused. |
| 118 | + 'typescript/no-unused-vars': 'error', |
| 119 | + |
| 120 | + // Disallow the use of variables before they are defined |
| 121 | + // This rule will warn when it encounters a reference to an identifier that has not yet been |
| 122 | + // declared. |
| 123 | + 'typescript/no-use-before-define': ['error', { |
| 124 | + functions: false, |
| 125 | + classes: false, |
| 126 | + typedefs: false, |
| 127 | + }], |
| 128 | + |
| 129 | + // Disallows the use of require statements except in import statements |
| 130 | + // In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 |
| 131 | + // style imports or import foo = require("foo") imports. |
| 132 | + 'typescript/no-var-requires': 'error', |
| 133 | + |
| 134 | + // Require the use of the namespace keyword instead of the module keyword to declare custom |
| 135 | + // TypeScript modules |
| 136 | + // In an effort to prevent further confusion between custom TypeScript modules and the new |
| 137 | + // ES2015 modules, starting with TypeScript v1.5 the keyword namespace is now the preferred way |
| 138 | + // to declare custom TypeScript modules. |
| 139 | + 'typescript/prefer-namespace-keyword': 'warn', |
| 140 | + |
| 141 | + // Require consistent spacing around type annotations |
| 142 | + // This rule aims to enforce specific spacing patterns around type annotations and function |
| 143 | + // types in type literals. |
| 144 | + 'typescript/type-annotation-spacing': 'warn', |
| 145 | + }, |
| 146 | +} |
0 commit comments