Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Add typescript linting. #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.9.0
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test": "npm run lint && npm run smoke"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^1.4.2",
"babel-eslint": "^10.0.0",
"chalk": "^2.4.1",
"eslint-import-resolver-babel-module": "^5.0.0-beta.0",
Expand Down
6 changes: 6 additions & 0 deletions rules/errors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var hasTypescript = require('../util/babel').hasTypescript();

module.exports = {
// For complete listing of rules and what they do, check out the docs.
// See: https://github.com/eslint/eslint/tree/master/docs/rules
Expand Down Expand Up @@ -190,3 +192,7 @@ module.exports = {
'block-scoped-var': 2,
},
};

if (hasTypescript) {
module.exports.rules['no-unused-vars'] = 0;
}
41 changes: 41 additions & 0 deletions rules/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var hasPrettier = require('../util/babel').hasPrettier();

module.exports = {
rules: {
'metalab/typescript/adjacent-overload-signatures': 'error',
'metalab/typescript/array-type': 'error',
'metalab/typescript/ban-types': 'error',
'metalab/typescript/camelcase': 'error',
'metalab/typescript/class-name-casing': 'error',
'metalab/typescript/explicit-function-return-type': 'warn',
'metalab/typescript/explicit-member-accessibility': 'error',
'metalab/typescript/indent': hasPrettier ? 'off' : 'error',
'metalab/typescript/interface-name-prefix': 'error',
'metalab/typescript/member-delimiter-style': 'error',
'metalab/typescript/no-angle-bracket-type-assertion': 'error',
'metalab/typescript/no-array-constructor': 'error',
'metalab/typescript/no-empty-interface': 'error',
'metalab/typescript/no-explicit-any': 'warn',
'metalab/typescript/no-inferrable-types': 'error',
'metalab/typescript/no-misused-new': 'error',
'metalab/typescript/no-namespace': 'error',
'metalab/typescript/no-non-null-assertion': 'error',
'metalab/typescript/no-object-literal-type-assertion': 'error',
'metalab/typescript/no-parameter-properties': 'error',
'metalab/typescript/no-triple-slash-reference': 'error',
'metalab/typescript/no-unused-vars': [
2,
{
// TODO: Maybe add `caughtErrors: "all"`
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'metalab/typescript/no-use-before-define': 'error',
'metalab/typescript/no-var-requires': 'error',
'metalab/typescript/prefer-interface': 'error',
'metalab/typescript/prefer-namespace-keyword': 'error',
'metalab/typescript/type-annotation-spacing': 'error',
},
};
Empty file added test/smoke/typescript/.eslintrc
Empty file.
3 changes: 3 additions & 0 deletions test/smoke/typescript/a.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const Test = (a: number): string => {
return (a + 5).toString();
};
1 change: 1 addition & 0 deletions test/smoke/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import {Test} from './a';
25 changes: 20 additions & 5 deletions util/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ exports.hasPrettier = function() {
return false;
};

exports.hasTypescript = function() {
// Determine if we are using typescript or not.
try {
resolve.sync('typescript', {
basedir: basedir,
});
return true;
} catch (err) {
// If we can't load prettier then stop caring.
}
return false;
};

exports.hasBabel = function() {
// Determine if we are using babel 7+ or not.
try {
Expand All @@ -40,6 +53,7 @@ exports.hasBabel = function() {
};

exports.hasBabelResolver = function() {
var message;
// Determine if we are using babel resolver or not.
try {
resolve.sync('babel-plugin-module-resolver', {
Expand All @@ -50,12 +64,13 @@ exports.hasBabelResolver = function() {
} catch (err) {
if (/SyntaxError/.test(err.toString())) {
if (/v4/.test(process.version)) {
console.log( // eslint-disable-line no-console
chalk.red('error'),
message = [
'babel-plugin-module-resolver does not work with node@4\n',
'See: ' +
'https://github.com/tleunen/babel-plugin-module-resolver/pull/222'
);
'See:',
'https://github.com/tleunen/babel-plugin-module-resolver/pull/222',
].join(' ');
// eslint-disable-next-line no-console
console.log(chalk.red('error'), message);
process.exit(1);
}
}
Expand Down