diff --git a/.eslintrc.yml b/.eslintrc.yml index 473a6b7..9263db0 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1 +1 @@ -extends: '.' +extends: './javascript.js' diff --git a/__snapshots__/test.js.snap b/__snapshots__/test.js.snap index ea9b188..0acc5cb 100644 --- a/__snapshots__/test.js.snap +++ b/__snapshots__/test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lints all fixtures: component.js 1`] = ` +exports[`lints all JS fixtures: component.js 1`] = ` Array [ Object { "column": 7, @@ -12,11 +12,9 @@ Array [ ] `; -exports[`lints all fixtures: exports.js 1`] = `Array []`; +exports[`lints all JS fixtures: exports.js 1`] = `Array []`; -exports[`lints all fixtures: exports.ts 1`] = `Array []`; - -exports[`lints all fixtures: import.js 1`] = ` +exports[`lints all JS fixtures: import.js 1`] = ` Array [ Object { "column": 25, @@ -32,22 +30,17 @@ Array [ "rule": "import/no-unresolved", "severity": 2, }, -] -`; - -exports[`lints all fixtures: import.ts 1`] = ` -Array [ Object { - "column": 27, - "line": 2, - "message": "Unable to resolve path to module './nonexistent'.", - "rule": "import/no-unresolved", + "column": 19, + "line": 5, + "message": "Useless path segments for \\"../js/exports\\", should be \\"./exports\\"", + "rule": "import/no-useless-path-segments", "severity": 2, }, ] `; -exports[`lints all fixtures: prop-types.js 1`] = ` +exports[`lints all JS fixtures: prop-types.js 1`] = ` Array [ Object { "column": 5, @@ -73,26 +66,7 @@ Array [ ] `; -exports[`lints all fixtures: prop-types.tsx 1`] = ` -Array [ - Object { - "column": 16, - "line": 4, - "message": "Missing return type on function.", - "rule": "@typescript-eslint/explicit-function-return-type", - "severity": 2, - }, - Object { - "column": 3, - "line": 33, - "message": "defaultProp \\"requiredPropWithDefault\\" defined for isRequired propType.", - "rule": "react/default-props-match-prop-types", - "severity": 2, - }, -] -`; - -exports[`lints all fixtures: variables.js 1`] = ` +exports[`lints all JS fixtures: variables.js 1`] = ` Array [ Object { "column": 24, @@ -125,7 +99,47 @@ Array [ ] `; -exports[`lints all fixtures: variables.ts 1`] = ` +exports[`lints all TS fixtures: exports.ts 1`] = `Array []`; + +exports[`lints all TS fixtures: import.ts 1`] = ` +Array [ + Object { + "column": 27, + "line": 2, + "message": "Unable to resolve path to module './nonexistent'.", + "rule": "import/no-unresolved", + "severity": 2, + }, + Object { + "column": 19, + "line": 5, + "message": "Useless path segments for \\"../ts/exports\\", should be \\"./exports\\"", + "rule": "import/no-useless-path-segments", + "severity": 2, + }, +] +`; + +exports[`lints all TS fixtures: prop-types.tsx 1`] = ` +Array [ + Object { + "column": 16, + "line": 4, + "message": "Missing return type on function.", + "rule": "@typescript-eslint/explicit-function-return-type", + "severity": 2, + }, + Object { + "column": 3, + "line": 33, + "message": "defaultProp \\"requiredPropWithDefault\\" defined for isRequired propType.", + "rule": "react/default-props-match-prop-types", + "severity": 2, + }, +] +`; + +exports[`lints all TS fixtures: variables.ts 1`] = ` Array [ Object { "column": 24, diff --git a/fixtures/component.js b/fixtures/js/component.js similarity index 100% rename from fixtures/component.js rename to fixtures/js/component.js diff --git a/fixtures/exports.js b/fixtures/js/exports.js similarity index 100% rename from fixtures/exports.js rename to fixtures/js/exports.js diff --git a/fixtures/import.js b/fixtures/js/import.js similarity index 84% rename from fixtures/import.js rename to fixtures/js/import.js index 116a42a..6c9d16e 100644 --- a/fixtures/import.js +++ b/fixtures/js/import.js @@ -2,4 +2,4 @@ import something, {foo, baz} from './exports' // baz is not exported import somethingElse from './nonexistent' // file does not exist export {foo, baz, something, somethingElse} -export {bar} from './exports' +export {bar} from '../js/exports' diff --git a/fixtures/prop-types.js b/fixtures/js/prop-types.js similarity index 100% rename from fixtures/prop-types.js rename to fixtures/js/prop-types.js diff --git a/fixtures/variables.js b/fixtures/js/variables.js similarity index 100% rename from fixtures/variables.js rename to fixtures/js/variables.js diff --git a/fixtures/exports.ts b/fixtures/ts/exports.ts similarity index 100% rename from fixtures/exports.ts rename to fixtures/ts/exports.ts diff --git a/fixtures/import.ts b/fixtures/ts/import.ts similarity index 84% rename from fixtures/import.ts rename to fixtures/ts/import.ts index 116a42a..8f1390a 100644 --- a/fixtures/import.ts +++ b/fixtures/ts/import.ts @@ -2,4 +2,4 @@ import something, {foo, baz} from './exports' // baz is not exported import somethingElse from './nonexistent' // file does not exist export {foo, baz, something, somethingElse} -export {bar} from './exports' +export {bar} from '../ts/exports' diff --git a/fixtures/prop-types.tsx b/fixtures/ts/prop-types.tsx similarity index 100% rename from fixtures/prop-types.tsx rename to fixtures/ts/prop-types.tsx diff --git a/fixtures/variables.ts b/fixtures/ts/variables.ts similarity index 100% rename from fixtures/variables.ts rename to fixtures/ts/variables.ts diff --git a/index.js b/index.js index e993f43..5b4ac62 100644 --- a/index.js +++ b/index.js @@ -1,133 +1,28 @@ module.exports = { - extends: ['airbnb', 'airbnb/hooks', 'prettier', 'prettier/react'], - plugins: ['prettier'], - parser: 'babel-eslint', - env: { - // allow browser globals - browser: true, - }, + extends: [ + require.resolve('./javascript'), + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:import/typescript', + 'prettier/@typescript-eslint', + ], rules: { - // https://github.com/prettier/eslint-config-prettier#arrow-body-style-and-prefer-arrow-callback - 'arrow-body-style': [2, 'as-needed', {requireReturnForObjectLiteral: false}], - - // ensure that default, named, and namespaced imports have been exported by the target file - 'import/default': 2, - 'import/namespace': [2, {allowComputed: true}], - - // require import groups to be ordered by specificity and separated by linebreaks - 'import/order': [2, {'newlines-between': 'always'}], - - // allow non-ID-linked