From acfb6e926f9324210d71ce1c8d453d17d707a9bd Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 14 Jan 2019 21:54:12 -0500 Subject: [PATCH] jk, test against eslint 2/3 but skip Typescript tests. also bumped babel-eslint --- .travis.yml | 18 +-- package.json | 2 +- src/rules/no-amd.js | 44 +++--- tests/src/core/getExports.js | 5 +- tests/src/rules/named.js | 190 ++++++++++++------------ tests/src/rules/newline-after-import.js | 3 +- tests/src/utils.js | 11 ++ 7 files changed, 146 insertions(+), 127 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03de81c6d..75f2e67ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ os: linux env: - ESLINT_VERSION=5 - ESLINT_VERSION=4 - # - ESLINT_VERSION=3 - # - ESLINT_VERSION=2 + - ESLINT_VERSION=3 + - ESLINT_VERSION=2 # osx backlog is often deep, so to be polite we can just hit these highlights matrix: @@ -38,14 +38,12 @@ matrix: - os: osx env: ESLINT_VERSION=4 node_js: 8 - - # the following combos fail TypeScript tests - # - os: osx - # env: ESLINT_VERSION=3 - # node_js: 6 - # - os: osx - # env: ESLINT_VERSION=2 - # node_js: 4 + - os: osx + env: ESLINT_VERSION=3 + node_js: 6 + - os: osx + env: ESLINT_VERSION=2 + node_js: 4 exclude: - node_js: '4' diff --git a/package.json b/package.json index 58618e233..fd0ead0c8 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "homepage": "https://github.com/benmosher/eslint-plugin-import", "devDependencies": { - "babel-eslint": "8.0.x", + "babel-eslint": "^10.0.1", "babel-plugin-istanbul": "^4.1.6", "babel-preset-es2015-argon": "latest", "babel-register": "^6.26.0", diff --git a/src/rules/no-amd.js b/src/rules/no-amd.js index df0d3aeb2..394244341 100644 --- a/src/rules/no-amd.js +++ b/src/rules/no-amd.js @@ -10,35 +10,35 @@ import docsUrl from '../docsUrl' //------------------------------------------------------------------------------ module.exports = { - meta: { - type: 'suggestion', - docs: { - url: docsUrl('no-amd'), - }, + meta: { + type: 'suggestion', + docs: { + url: docsUrl('no-amd'), }, + }, - create: function (context) { + create: function (context) { + return { + 'CallExpression': function (node) { + if (context.getScope().type !== 'module') return - return { + console.log("got scope", context.getScope().type) - 'CallExpression': function (node) { - if (context.getScope().type !== 'module') return + if (node.callee.type !== 'Identifier') return + if (node.callee.name !== 'require' && + node.callee.name !== 'define') return - if (node.callee.type !== 'Identifier') return - if (node.callee.name !== 'require' && - node.callee.name !== 'define') return + // todo: capture define((require, module, exports) => {}) form? + if (node.arguments.length !== 2) return - // todo: capture define((require, module, exports) => {}) form? - if (node.arguments.length !== 2) return + const modules = node.arguments[0] + if (modules.type !== 'ArrayExpression') return - const modules = node.arguments[0] - if (modules.type !== 'ArrayExpression') return + // todo: check second arg type? (identifier or callback) - // todo: check second arg type? (identifier or callback) + context.report(node, `Expected imports instead of AMD ${node.callee.name}().`) + }, + } - context.report(node, `Expected imports instead of AMD ${node.callee.name}().`) - }, - } - - }, + }, } diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index 3bda3d3db..b33d548f0 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -3,7 +3,7 @@ import ExportMap from '../../../src/ExportMap' import * as fs from 'fs' -import { getFilename } from '../utils' +import { getFilename, skipESLints } from '../utils' import * as unambiguous from 'eslint-module-utils/unambiguous' describe('ExportMap', function () { @@ -310,7 +310,7 @@ describe('ExportMap', function () { }) - context('alternate parsers', function () { + skipESLints([2, 3])('alternate parsers', function () { const configs = [ // ['string form', { 'typescript-eslint-parser': '.ts' }], @@ -318,6 +318,7 @@ describe('ExportMap', function () { ] configs.forEach(([description, parserConfig]) => { + describe(description, function () { const context = Object.assign({}, fakeContext, { settings: { diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index ed6dc9e04..7ffd929e1 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -1,4 +1,4 @@ -import { test, SYNTAX_CASES } from '../utils' +import { test, SYNTAX_CASES, skipESLints } from '../utils' import { RuleTester } from 'eslint' import { CASE_SENSITIVE_FS } from 'eslint-module-utils/resolve' @@ -83,70 +83,6 @@ ruleTester.run('named', rule, { parser: 'babel-eslint', }), - // TypeScript - test({ - code: 'import { MyType } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { Foo } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { Bar } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { getFoo } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: 'import { MyEnum } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: ` - import { MyModule } from "./typescript" - MyModule.ModuleFunction() - `, - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - test({ - code: ` - import { MyNamespace } from "./typescript" - MyNamespace.NSModule.NSModuleFunction() - `, - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - }), - // jsnext test({ code: '/*jsnext*/ import { createStore } from "redux"', @@ -246,32 +182,6 @@ ruleTester.run('named', rule, { // }], // }), - // TypeScript - test({ - code: 'import { MissingType } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - errors: [{ - message: "MissingType not found in './typescript'", - type: 'Identifier', - }], - }), - test({ - code: 'import { NotExported } from "./typescript"', - parser: 'typescript-eslint-parser', - settings: { - 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, - 'import/resolver': { 'eslint-import-resolver-typescript': true }, - }, - errors: [{ - message: "NotExported not found in './typescript'", - type: 'Identifier', - }], - }), - test({ code: 'import { type MyOpaqueType, MyMissingClass } from "./flowtypes"', parser: 'babel-eslint', @@ -342,3 +252,101 @@ ruleTester.run('named (export *)', rule, { }), ], }) + + +skipESLints([2, 3])("Typescript", function () { + // Typescript + ruleTester.run("named", rule, { + valid: [ + test({ + code: 'import { MyType } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { Foo } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { Bar } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { getFoo } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: 'import { MyEnum } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: ` + import { MyModule } from "./typescript" + MyModule.ModuleFunction() + `, + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + test({ + code: ` + import { MyNamespace } from "./typescript" + MyNamespace.NSModule.NSModuleFunction() + `, + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + }), + ], + + invalid: [ + test({ + code: 'import { MissingType } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + errors: [{ + message: "MissingType not found in './typescript'", + type: 'Identifier', + }], + }), + test({ + code: 'import { NotExported } from "./typescript"', + parser: 'typescript-eslint-parser', + settings: { + 'import/parsers': { 'typescript-eslint-parser': ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + errors: [{ + message: "NotExported not found in './typescript'", + type: 'Identifier', + }], + }), + ] + }) +}) diff --git a/tests/src/rules/newline-after-import.js b/tests/src/rules/newline-after-import.js index 00ebfa432..730cef363 100644 --- a/tests/src/rules/newline-after-import.js +++ b/tests/src/rules/newline-after-import.js @@ -153,8 +153,9 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), { }, { code: `//issue 592 + export default @SomeDecorator(require('./some-file')) - export default class App {} + class App {} `, parserOptions: { sourceType: 'module' }, parser: 'babel-eslint', diff --git a/tests/src/utils.js b/tests/src/utils.js index fe04d684e..9ec1b3e48 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -29,6 +29,17 @@ export function getFilename(file) { return path.join(__dirname, '..', 'files', file || 'foo.js') } +/** + * skip tests iff ESLINT_VERSION is in provided `versions` array + */ +export function skipESLints(versions) { + if (!versions.includes(+process.env.ESLINT_VERSION)) { + return describe + } else { + return describe.skip + } +} + /** * to be added as valid cases just to ensure no nullable fields are going * to crash at runtime