Lint
19. Feber 2020
Lint bezeichnet eine statische Code-Analyse. Im Deutschen wird oft das Verb „linten“ verwendet. Früher (und auch heute noch) haben Compiler gewisse Schwächen und erkennen vieles nicht als Fehler. Der Code mag zwar syntaktisch korrekt sein, allerdings kann er z.B. zu unerwünschten Nebenwirkungen führen. Linter können aber auch zum Durchsetzen von Coding Guidelines verwendet werden.
Gerade bei der Entwicklung von JavaScript macht es Sinn einen Linter, in diesem Fall ESLint, einzusetzen. Je nach Konfiguration wird der Entwickler damit auf Probleme, Schwächen oder Unschönheiten hingewiesen.
Für TypeScript gibt es ebenfalls einen Linter – tslint. Nachfolgend eine von mir erstellte Beispielkonfiguration:
{
"rules": {
"no-empty": true,
"adjacent-overload-signatures": true,
"member-access": [true, "no-public"],
"member-ordering": [true, {
"order": [
"private-static-field",
"private-instance-field",
"public-constructor",
"private-constructor",
"public-static-field",
"public-instance-field",
"public-instance-method",
"protected-instance-method",
"private-instance-method"
]
}],
"no-magic-numbers": true,
"no-namespace": true,
"no-var-requires": true,
"only-arrow-functions": true,
"prefer-for-of": true,
"ban-comma-operator": true,
"curly": true,
"no-conditional-assignment": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-misused-new": true,
"no-shadowed-variable": true,
"no-sparse-arrays": true,
"no-string-throw": true,
"no-switch-case-fall-through": true,
"no-this-assignment": true,
"no-unnecessary-class": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-var-keyword": true,
"prefer-conditional-expression": true,
"static-this": true,
"switch-default": true,
"cyclomatic-complexity": [true, 20],
"no-require-imports": true,
"prefer-const": true,
"arrow-return-shorthand": true,
"binary-expression-operand-order": true,
"class-name": true,
"file-name-casing": [true, "kebab-case"],
"interface-name": [true, "always-prefix"],
"newline-per-chained-call": true,
"one-line": [
true,
"check-catch",
"check-finally",
"check-else",
"check-whitespace",
"check-open-brace"
],
"prefer-switch": true,
"space-before-function-paren": [true, "never"],
"space-within-parens": true,
"type-literal-delimiter": true,
"variable-name": {
"options": [
"ban-keywords",
"check-format",
"allow-leading-underscore"
]
},
"arrow-parens": true,
"import-spacing": true,
"indent": [true, "spaces", 2],
"new-parens": true,
"no-consecutive-blank-lines": true,
"quotemark": [true, "double"],
"semicolon": [true, "always"]
}
}