From 4234e53ef9dd71d319e643315cbf2ec15c6126e5 Mon Sep 17 00:00:00 2001 From: Izaak Schroeder Date: Tue, 12 Mar 2019 14:34:58 -0700 Subject: [PATCH] wip --- .node-version | 1 + package-lock.json | 64 +++++++++++++++++++++++++++++++++ package.json | 1 + rules/errors.js | 6 ++++ rules/typescript.js | 41 +++++++++++++++++++++ test/smoke/typescript/.eslintrc | 0 test/smoke/typescript/a.tsx | 3 ++ test/smoke/typescript/index.ts | 1 + util/babel.js | 18 ++++++++-- 9 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 .node-version create mode 100644 rules/typescript.js create mode 100644 test/smoke/typescript/.eslintrc create mode 100644 test/smoke/typescript/a.tsx create mode 100644 test/smoke/typescript/index.ts diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..6b3621d --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +11.9.0 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 86808f2..3b844f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -241,6 +241,47 @@ } } }, + "@typescript-eslint/eslint-plugin": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.4.2.tgz", + "integrity": "sha512-6WInypy/cK4rM1dirKbD5p7iFW28DbSRKT/+PGn+DYzBWEvHq5KnZAqQ5cX25JBc0qMkFxJNxNfBbFXJyyzVcw==", + "requires": { + "@typescript-eslint/parser": "1.4.2", + "@typescript-eslint/typescript-estree": "1.4.2", + "requireindex": "^1.2.0", + "tsutils": "^3.7.0" + } + }, + "@typescript-eslint/parser": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.4.2.tgz", + "integrity": "sha512-OqLkY9295DXXaWToItUv3olO2//rmzh6Th6Sc7YjFFEpEuennsm5zhygLLvHZjPxPlzrQgE8UDaOPurDylaUuw==", + "requires": { + "@typescript-eslint/typescript-estree": "1.4.2", + "eslint-scope": "^4.0.0", + "eslint-visitor-keys": "^1.0.0" + }, + "dependencies": { + "eslint-scope": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.2.tgz", + "integrity": "sha512-5q1+B/ogmHl8+paxtOKx38Z8LtWkVGuNt3+GQNErqwLl6ViNp/gdJGMCjZNxZ8j/VYjDNZ2Fo+eQc1TAVPIzbg==", + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + } + } + }, + "@typescript-eslint/typescript-estree": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.4.2.tgz", + "integrity": "sha512-wKgi/w6k1v3R4b6oDc20cRWro2gBzp0wn6CAeYC8ExJMfvXMfiaXzw2tT9ilxdONaVWMCk7B9fMdjos7bF/CWw==", + "requires": { + "lodash.unescape": "4.0.1", + "semver": "5.5.0" + } + }, "acorn": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz", @@ -1413,6 +1454,11 @@ "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", "integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40=" }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=" + }, "lodash.upperfirst": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz", @@ -1769,6 +1815,11 @@ "resolve-from": "^1.0.0" } }, + "requireindex": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==" + }, "reselect": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/reselect/-/reselect-3.0.1.tgz", @@ -2028,6 +2079,19 @@ "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=" }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==" + }, + "tsutils": { + "version": "3.9.1", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.9.1.tgz", + "integrity": "sha512-hrxVtLtPqQr//p8/msPT1X1UYXUjizqSit5d9AQ5k38TcV38NyecL5xODNxa73cLe/5sdiJ+w1FqzDhRBA/anA==", + "requires": { + "tslib": "^1.8.1" + } + }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", diff --git a/package.json b/package.json index 3af3ea9..7d1e1bf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/rules/errors.js b/rules/errors.js index e10ad7b..b6ad2c1 100644 --- a/rules/errors.js +++ b/rules/errors.js @@ -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 @@ -190,3 +192,7 @@ module.exports = { 'block-scoped-var': 2, }, }; + +if (hasTypescript) { + module.exports.rules['no-unused-vars'] = 0; +} diff --git a/rules/typescript.js b/rules/typescript.js new file mode 100644 index 0000000..dcd3cc5 --- /dev/null +++ b/rules/typescript.js @@ -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', + }, +}; diff --git a/test/smoke/typescript/.eslintrc b/test/smoke/typescript/.eslintrc new file mode 100644 index 0000000..e69de29 diff --git a/test/smoke/typescript/a.tsx b/test/smoke/typescript/a.tsx new file mode 100644 index 0000000..39f2a8d --- /dev/null +++ b/test/smoke/typescript/a.tsx @@ -0,0 +1,3 @@ +export const Test = (a: number): string => { + return (a + 5).toString(); +}; diff --git a/test/smoke/typescript/index.ts b/test/smoke/typescript/index.ts new file mode 100644 index 0000000..5dde52e --- /dev/null +++ b/test/smoke/typescript/index.ts @@ -0,0 +1 @@ +import {Test} from './a'; diff --git a/util/babel.js b/util/babel.js index 9d2b9fd..a40b853 100644 --- a/util/babel.js +++ b/util/babel.js @@ -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 { @@ -50,11 +63,12 @@ exports.hasBabelResolver = function() { } catch (err) { if (/SyntaxError/.test(err.toString())) { if (/v4/.test(process.version)) { - console.log( // eslint-disable-line no-console + console.log( + // eslint-disable-line no-console chalk.red('error'), 'babel-plugin-module-resolver does not work with node@4\n', 'See: ' + - 'https://github.com/tleunen/babel-plugin-module-resolver/pull/222' + 'https://github.com/tleunen/babel-plugin-module-resolver/pull/222', ); process.exit(1); }