Add TypeScript ruleset & config
Closed this issue · 1 comments
robertrossmann commented
There is a parser for TS: https://github.com/eslint/typescript-eslint-parser
And a ruleset: https://github.com/nzakas/eslint-plugin-typescript
And There is this thing, although with not much info about usage: https://github.com/JamesHenry/eslint-plugin-tslint
robertrossmann commented
For now, here are the steps necessary to make it work. Everything seems to be working correctly. I have not tested if the ESLint's rules actually work on TS-specific code constructs, but they should definitely work fine on constructs present in normal JS. 🎉
I'll be incorporating this into the module as a new ruleset later.
npm i -D eslint@latest @strv/eslint-config-javascript@latest eslint-plugin-typescript@latest typescript-eslint-parser@latest// .eslintrc.js
'use strict'
module.exports = {
parser: 'typescript-eslint-parser',
extends: [
'@strv/javascript/environments/nodejs/v10',
'@strv/javascript/environments/nodejs/optional',
'@strv/javascript/coding-styles/recommended',
],
plugins: [
'typescript',
],
env: {
es6: true,
},
parserOptions: {
sourceType: 'module'
},
rules: {
// TS code is mostly self-documented and having JSDoc directives for everything is redundant
// when you can easily infer return values and argument types from the code itself.
'valid-jsdoc': 'off',
// Disabled because it generates false positives with interface declarations and TypeScript
// blows up anyway during compilation when it encouters an undefined variable.
'no-undef': 'off',
// Prevent TypeScript-specific constructs from being erroneously flagged as unused
'typescript/no-unused-vars': 'error',
// @TODO: Add the remaining rules from eslint-plugin-typescript
},
overrides: [{
files: ['**/*.test.ts'],
env: {
mocha: true
},
}],
}# .eslintignore
node_modules
.nyc_output
coverage
docs
# Choose whichever you use
out
distTo run ESLint on all source files: npx eslint --ext ts .