Skip to content

Commit

Permalink
add .json to default extensions list in Node resolver (fixes #333)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jun 21, 2016
1 parent 1c2913b commit 6c31d28
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
8 changes: 8 additions & 0 deletions resolvers/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Change Log
All notable changes to this resolver will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased
### Fixed
- find files with `.json` extensions (#333, thanks for noticing @jfmengels)
5 changes: 4 additions & 1 deletion resolvers/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ exports.resolve = function (source, file, config) {
}

function opts(file, config) {
return assign({},
return assign({
// more closely matches Node (#333)
extensions: ['.js', '.json'],
},
config,
{
// path.resolve will handle paths relative to CWD
Expand Down
Empty file added resolvers/node/test/data.json
Empty file.
8 changes: 8 additions & 0 deletions resolvers/node/test/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ describe("paths", function () {
.equal(path.resolve(__dirname, '../index.js'))
})
})

describe("default options", function () {
it("finds .json files", function () {
expect(node.resolve('./data', './test/file.js'))
.to.have.property('path')
.equal(path.resolve(__dirname, './data.json'))
})
})
8 changes: 2 additions & 6 deletions tests/src/rules/default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '../utils'
import { test, SYNTAX_CASES } from '../utils'
import { RuleTester } from 'eslint'

var ruleTester = new RuleTester()
Expand Down Expand Up @@ -66,11 +66,7 @@ ruleTester.run('default', rule, {
parser: 'babel-eslint',
}),

// JSON
test({
code: 'import foo from "./foobar.json";',
parser: 'babel-eslint',
}),
...SYNTAX_CASES,
],

invalid: [
Expand Down
6 changes: 0 additions & 6 deletions tests/src/rules/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ const valid = [
parser: 'babel-eslint',
}),

// JSON
test({
code: 'import foo from "./foobar.json";',
parser: 'babel-eslint',
}),

...SYNTAX_CASES,
]

Expand Down
7 changes: 6 additions & 1 deletion tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'

import assign from 'object-assign'
import { test } from '../utils'
import { test, SYNTAX_CASES } from '../utils'

import { RuleTester } from 'eslint'

Expand Down Expand Up @@ -347,3 +347,8 @@ ruleTester.run('no-unresolved electron', rule, {
}),
],
})

ruleTester.run('no-unresolved syntax verification', rule, {
valid: SYNTAX_CASES,
invalid:[],
})
10 changes: 10 additions & 0 deletions tests/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export const SYNTAX_CASES = [
settings: { 'import/extensions': ['.js'] }, // breaking: remove for v2
}),

// JSON
test({
code: 'import foo from "./foobar.json";',
settings: { 'import/extensions': ['.js'] }, // breaking: remove for v2
}),
test({
code: 'import foo from "./foobar";',
settings: { 'import/extensions': ['.js'] }, // breaking: remove for v2
}),

// issue #370: deep commonjs import
test({
code: 'import { foo } from "./issue-370-commonjs-namespace/bar"',
Expand Down

0 comments on commit 6c31d28

Please sign in to comment.