Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
angular-tslint-rules
Advanced tools
Shared TSLint & codelyzer rules to enforce a consistent code style for Angular development
Shared TSLint & codelyzer rules to enforce a consistent code style for Angular development
Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.
The value of the software produced is directly affected by the quality of the codebase, and not every developer might
For that purpose, we need to use static code analysis tools such as TSLint and codelyzer to check readability, maintainability, and functionality errors.
Although complying with these tools may seem to appear as undesired overhead or may limit creativity, it becomes easier for any new developers to read, preventing a lot of time/frustration spent figuring out the structure and characteristics of the code.
Containing a set of TSLint and codelyzer rules, angular-tslint-rules
has been compiled using many contributions
from colleagues, commercial/open-source projects and some other sources from the Internet, as well as years of development
using the Angular framework.
If you have questions, comments or suggestions, just create an issue on this repository. I'll try to revise and republish these rules with new insights, experiences and remarks in alignment with the updates on TSLint and codelyzer.
Note: The following set of rules depend on:
You can install angular-tslint-rules
using npm
npm install angular-tslint-rules --save
Note: You should have already installed TSLint and codelyzer.
To use these TSLint rules, use configuration inheritance via the extends
keyword.
A sample configuration is shown below, where tslint.json
lives adjacent to your node_modules
folder:
{
"rulesDirectory": [
"node_modules/codelyzer"
],
"extends": ["angular-tslint-rules"],
"rules": {
// override tslint rules here
...
}
}
"no-unnecessary-class": [
true,
"allow-constructor-only",
"allow-static-only",
"allow-empty-class"
]
public
keyword (this is the default accessibility level).private
and private static
members in classes should be denoted with the private
keyword."member-access": [
true,
"no-public"
]
"member-ordering": [
true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
]
"prefer-readonly": true
"adjacent-overload-signatures": [
true,
{
"ignore-accessors": true,
}
]
"unified-signatures": true
private
members that do not use this
."prefer-function-over-method": [
true,
"allow-public",
"allow-protected"
]
"no-unbound-method": [true, "ignore-static"]
this
keyword outside class context (including functions in methods)."no-invalid-this": [
true,
"check-function-in-method"
]
this
in static methods."static-this": true
this
to local variables."no-this-assignment": true
"unnecessary-constructor": true
super
method twice in a constructor (except in branched statements or nested class constructors)."no-duplicate-super": true
()
when invoking a constructor via the new keyword."new-parens": true
new
for classes."no-misused-new": true
String
, Number
, and Boolean
."no-construct": true
"no-empty-interface": true
foo(): void
over foo: () => void
in interfaces and types."prefer-method-signature": true
type T = { ... }
)."interface-over-type-literal": true
"function-constructor": true
"no-parameter-reassignment": true
"no-void-expression": true
return;
in void functions and return undefined;
in value-returning functions."return-undefined": true
arguments.callee
within a function, as it makes impossible various performance optimizations."no-arg": true
() => { }
functions."only-arrow-functions": true
()
around the function parameters (except if removing
them is allowed by TypeScript)."arrow-parens": [
true,
"ban-single-arg-parens"
]
() => x
over () => { return x; }
."arrow-return-shorthand": [
true,
"multiline"
]
f
over x => f(x)
."no-unnecessary-callback-wrapper": true
"unnecessary-bind": true
async
functions returning a Promise
."promise-function-async": true
async
(if the awaited value that is not a Promise
)."await-promise": true
async
must contain an await
or return
statement"no-async-without-await": true
return await
."no-return-await": true
Promise
."no-floating-promises": true
const
keyword where appropriate, for values that should never change.let
(maintain immutability)."prefer-const": true
var
keyword."no-var-keyword": true
"no-shadowed-variable": [
true,
{
"temporalDeadZone": false
}
]
"one-variable-per-declaration": [
true,
"ignore-for-loop"
]
"no-duplicate-variable": [
true,
"check-parameters"
]
var
/let
statement or destructuring initializer to be initialized to undefined
."no-unnecessary-initializer": true
package.json
."no-implicit-dependencies": true
import
statements with side-effect."no-import-side-effect": [
true,
{
"ignore-module": "(hammerjs|core-js|zone.js)"
}
]
import
statement keywords in alphabetical order."ordered-imports": [
true,
{
"import-sources-order": "case-insensitive",
"named-imports-order": "case-insensitive",
"grouped-imports": false
}
]
import
statement per module."no-duplicate-imports": true
require
statements at all (use ES6-style import
statement instead)."no-require-imports": true
"no-default-import": true,
"no-default-export": true
/// <reference path=> imports
statements at all (use ES6-style import
statement instead)."no-reference": true
any
)."typedef": [
true,
"call-signature",
"property-declaration"
]
"no-inferrable-types": true
"use-default-type-parameter": true
"no-object-literal-type-assertion": true
as Type
for type assertions over <Type>
."no-angle-bracket-type-assertion": true
"no-unnecessary-type-assertion": true
"callable-types": true
null
keyword, always return undefined
instead of a null
reference."no-null-keyword": true
null
and undefined
as members."no-null-undefined-union": true
"no-non-null-assertion": true
Array<type>
instead of type[]
."array-type": [
true,
"generic"
]
"prefer-object-spread": true
"object-literal-shorthand": true
"object-literal-key-quotes": [
true,
"as-needed"
]
"no-string-literal": true
''
for all strings, and use double-quotes ""
for strings within strings."quotemark": [
true,
"single",
"avoid-template",
"avoid-escape"
]
"prefer-template": true
"no-invalid-template-strings": true
===
and !==
operators whenever possible.
==
and!=
operators do type coercion, which can lead to headaches when debugging code.
"triple-equals": [
true,
"allow-null-check"
]
>
, >=
, <=
, <
) to compare non-numbers should be avoided."strict-comparisons": [
true,
{
"allow-object-equal-comparison": true,
"allow-string-order-comparison": false
}
]
+= 1
and -= 1
pre-unary operators over ++i
and --i
."increment-decrement": [
true,
"allow-post"
]
"restrict-plus-operands": true
"binary-expression-operand-order": true
delete
operator with dynamic key expressions."no-dynamic-delete": true
"no-bitwise": true
isNan
function to check NaN
references."use-isnan": true
if
, while
, and do while
statements should be
avoided."no-conditional-assignment": true
if
statement."prefer-conditional-expression": [
true,
"check-else-if"
]
3 === 3
, someVar === someVar
)."no-tautology-expression": true
x === true
)."no-boolean-literal-compare": true
break
, continue
, return
or throw
statement."unnecessary-else": [
true,
{
"allow-else-if": true
}
]
&&
or ||
)."strict-boolean-expressions": [
true,
"allow-undefined-union",
"allow-string",
"allow-enum",
"allow-number",
"allow-mix",
"allow-rhs"
]
for
statementwhile
loop over a standard for
loop without initializer, incrementor and/or termination condition."prefer-while": true
for-of
loop over a standard for
loop."prefer-for-of": true
for-in
statements with an if
statement (this prevents accidental iteration over properties inherited
from an object???s prototype)."forin": true
for-in
loop."no-for-in-array": true
switch
statement"switch-default": true
break
, return
, or throw
."no-switch-case-fall-through": true
"no-duplicate-switch-case": true
try
statementreturn
, continue
, break
and throws
in finally
blocks."no-unsafe-finally": true
"encoding": true
"cyclomatic-complexity": [
true,
20
]
"max-file-line-count": [true, 400]
"max-line-length": [
true,
{
"limit": 140,
"ignore-pattern": "^import |^export {(.*?)}|class [a-zA-Z]+ implements |// "
}
]
"indent": [
true,
"spaces",
2
]
"eofline": true
Always Use curly braces.
"curly": true
Whitespaces should be used in the following circumstances:
if
/else
/for
/while
) should be followed by one space..
, left parenthesis (
, and left bracket [
should be separated from
their operands by one space.!x, -x, +x, ~x, ++x, --x
and its
operand.|
, &
and its operand.{
and before the right curly brace }
containing import
statement keywords.,
,;
) in the control part of a for
statement should be followed with one space....
.{
followed by a right parenthesis )
should always separated by one space."whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-rest-spread",
"check-type",
"check-typecast",
"check-type-operator",
"check-preblock"
]
:
indicating the type declaration.:
and the type declaration."typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
]
(
of its parameter
list.)
and the =>
."space-before-function-paren": [
true,
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always",
"method": "never",
"constructor": "never"
}
]
"space-within-parens": 0
import
statement keywords."import-spacing": true
"no-trailing-whitespace": true
Empty lines improve code readability by allowing the developer to logically group code blocks.
"newline-before-return": true
"newline-per-chained-call": true
else
, catch
and finally
statements;
)
and the left curly {
brace that begins the
statement body.=>
and the left curly brace {
that begins the statement body.else
statements should indented to align with the line containing the closing brace for the if
statement.catch
and finally
statements should indented to align with the line containing the closing brace for the
try
statement."one-line": [
true,
"check-open-brace",
"check-whitespace",
"check-else",
"check-catch",
"check-finally"
]
"no-consecutive-blank-lines": [
true,
1
]
"semicolon": [
true,
"always",
"strict-bound-class-methods"
]
"align": [
true,
"elements",
"members",
"parameters",
"statements"
]
"trailing-comma": [
true,
{
"multiline": "never",
"singleline": "never",
"esSpecCompliant": true
}
]
"file-name-casing": [
true,
"kebab-case"
]
"class-name": true
I
prefix."interface-name": [
true,
"never-prefix"
]
_
characters."variable-name": [
true,
"check-format",
"allow-leading-underscore",
"require-const-for-all-caps",
"ban-keywords"
]
"comment-type": [
true,
"singleline",
"doc"
]
//
for all inline comments."comment-format": [
true,
"check-space"
]
/**
and end with */
."jsdoc-format": [
true,
"check-multiline-start"
]
"no-redundant-jsdoc": true
// @ts-ignore
comments."ban-ts-ignore": true
console
method (such messages are considered to be for debugging purposes and therefore might
ship to the production environment)."no-console": [
true,
"log",
"debug",
"info",
"time",
"timeEnd",
"trace"
]
debugger
statement (this might cause the environment to stop execution and start up a debugger,
if not omitted on the production code)."no-debugger": true
eval
function (using eval
on untrusted code might open a program up to several different injection
attacks)."no-eval": true
Error
s produce proper stack traces)."no-string-throw": true
namespace {}
is outdated)."no-namespace": true
module {}
is outdated)."no-internal-module": true
0
(instead of .
).0
."number-literal-format": true
radix
parameter to be specified when calling parseInt
."radix": true
"no-unused-expression": [
true,
"allow-fast-null-checks"
]
{}
in the code."no-empty": true
"no-sparse-arrays": true
"ban-comma-operator": true
"template-banana-in-box": true,
"contextual-lifecycle": true,
"contextual-decorator": true,
"no-pipe-impure": true,
"template-no-negated-async": true,
"template-i18n": [
true,
"check-id",
"check-text"
],
"component-max-inline-declarations": true,
"no-attribute-decorator": true,
"no-conflicting-lifecycle": true,
"no-forward-ref": true,
"no-input-rename": true,
"no-lifecycle-call": true,
"no-output-native": true,
"no-output-on-prefix": true,
"no-output-rename": true,
"template-no-call-expression": true,
"no-unused-css": true,
"prefer-output-readonly": true,
"template-conditional-complexity": true,
"template-cyclomatic-complexity": true,
"template-use-track-by-function": true,
"use-lifecycle-interface": true,
"use-pipe-decorator": true,
"use-pipe-transform-interface": true,
"use-component-view-encapsulation": true,
"component-class-suffix": true,
"component-selector": [
true,
"element",
[
"ngx",
"test"
],
"kebab-case"
],
"directive-class-suffix": true,
"directive-selector": [
true,
"attribute",
[
"ngx",
"test"
],
"camelCase"
],
"import-destructuring-spacing": true,
"no-queries-metadata-property": true,
"prefer-inline-decorator": true,
"no-host-metadata-property": true,
"no-inputs-metadata-property": true,
"no-outputs-metadata-property": true
If you want to file a bug, contribute some code, or improve documentation, please read up on the following contribution guidelines:
The MIT License (MIT)
Copyright (c) 2018 Burak Tasci
FAQs
Shared TSLint & codelyzer rules to enforce a consistent code style for Angular development
The npm package angular-tslint-rules receives a total of 940 weekly downloads. As such, angular-tslint-rules popularity was classified as not popular.
We found that angular-tslint-rules demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.