Skip to content

Commit

Permalink
jk, test against eslint 2/3 but skip Typescript tests.
Browse files Browse the repository at this point in the history
also bumped babel-eslint
  • Loading branch information
Ben Mosher authored and ljharb committed Jan 15, 2019
1 parent b686f9d commit acfb6e9
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 127 deletions.
18 changes: 8 additions & 10 deletions .travis.yml
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
44 changes: 22 additions & 22 deletions src/rules/no-amd.js
Expand Up @@ -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}().`)
},
}

},
},
}
5 changes: 3 additions & 2 deletions tests/src/core/getExports.js
Expand Up @@ -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 () {
Expand Down Expand Up @@ -310,14 +310,15 @@ describe('ExportMap', function () {

})

context('alternate parsers', function () {
skipESLints([2, 3])('alternate parsers', function () {

const configs = [
// ['string form', { 'typescript-eslint-parser': '.ts' }],
['array form', { 'typescript-eslint-parser': ['.ts', '.tsx'] }],
]

configs.forEach(([description, parserConfig]) => {

describe(description, function () {
const context = Object.assign({}, fakeContext,
{ settings: {
Expand Down
190 changes: 99 additions & 91 deletions 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'
Expand Down Expand Up @@ -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"',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
}],
}),
]
})
})
3 changes: 2 additions & 1 deletion tests/src/rules/newline-after-import.js
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions tests/src/utils.js
Expand Up @@ -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
Expand Down

0 comments on commit acfb6e9

Please sign in to comment.