Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…mport

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
ntdb committed Nov 2, 2016
2 parents 27836ba + edbb570 commit db1343f
Show file tree
Hide file tree
Showing 28 changed files with 229 additions and 57 deletions.
9 changes: 7 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
plugins:
- import
extends:
- eslint:recommended
- plugin:import/errors
- plugin:import/warnings
- plugin:import/recommended

env:
node: true
Expand All @@ -24,6 +25,10 @@ rules:
- single
- allowTemplateLiterals: true

# dog fooding
import/no-extraneous-dependencies: "error"
import/unambiguous: "off"

settings:
import/resolver:
node:
Expand Down
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Added
- Add [`no-named-default`] rule: style-guide rule to report use of unnecessarily named default imports

### Fixed
- [`prefer-default-export`] handles re-exported default exports ([#609])
- Fix crash when using `newline-after-import` with decorators ([#592])
- Properly report `newline-after-import` when next line is a decorator

## [2.0.1] - 2016-10-06
### Fixed
- Fixed code that relied on removed dependencies. ([#604])

## [2.0.0]! - 2016-09-30
### Added
Expand All @@ -26,7 +35,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Changed
- `imports-first` is renamed to [`first`]. `imports-first` alias will continue to
exist, but may be removed in a future major release.
- Case-sensitivity: now specifically (and optionally) reported by [`no-unresolved`].
- Case-sensitivity: now specifically (and optionally) reported by [`no-unresolved`].
Other rules will ignore case-mismatches on paths on case-insensitive filesystems. ([#311])

### Fixed
Expand Down Expand Up @@ -396,6 +405,9 @@ for info on changes for earlier releases.
[#157]: https://github.com/benmosher/eslint-plugin-import/pull/157
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314

[#609]: https://github.com/benmosher/eslint-plugin-import/issues/609
[#604]: https://github.com/benmosher/eslint-plugin-import/issues/604
[#592]: https://github.com/benmosher/eslint-plugin-import/issues/592
[#577]: https://github.com/benmosher/eslint-plugin-import/issues/577
[#570]: https://github.com/benmosher/eslint-plugin-import/issues/570
[#567]: https://github.com/benmosher/eslint-plugin-import/issues/567
Expand Down Expand Up @@ -444,7 +456,8 @@ for info on changes for earlier releases.
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.0.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.0.1...HEAD
[2.0.1]: https://github.com/benmosher/eslint-plugin-import/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.16.0...v2.0.0
[1.16.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.15.0...v1.16.0
[1.15.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.14.0...v1.15.0
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
[![npm](https://img.shields.io/npm/v/eslint-plugin-import.svg)](https://www.npmjs.com/package/eslint-plugin-import)
[![npm downloads](https://img.shields.io/npm/dt/eslint-plugin-import.svg?maxAge=2592000)](http://www.npmtrends.com/eslint-plugin-import)

# a quick note

I want to apologize: I have been pretty unresponsive the last few weeks. My wife just birthed our second son and is still recovering on bed rest, so I'm barely holding my home and day job together, and re-discovering what an amazing force for awesome she is for our family, as I'm fumbling through picking up the slack. 😅

I am hoping to be back in action on this in the next week or two, but I need to focus on my family and work in the immediate term. Fortunately, @jfmengels is a fantastic co-maintainer and has been doing a great job responding to new issues in my absence.

Thanks for your patience! 😎

-- @benmosher

(now, back to the normal README:)

This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names. All the goodness that the ES2015+ static module syntax intends to provide, marked up in your editor.

**IF YOU ARE USING THIS WITH SUBLIME**: see the [bottom section](#sublimelinter-eslint) for important info.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-extraneous-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You can set the options like this:
You can also use an array of globs instead of literal booleans:

```js
"import/no-extraneous-dependencies": ["error", {"devDependencies": ['**/*.test.js', '**/*.spec.js']}]
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/*.spec.js"]}]
```

When using an array of globs, the setting will be activated if the name of the file being linted matches a single glob in the array.
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unambiguous.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# unambiguous

Warn if a `module` could be mistakely parsed as a `script` by a consumer leveraging
Warn if a `module` could be mistakenly parsed as a `script` by a consumer leveraging
[Unambiguous JavaScript Grammar] to determine correct parsing goal.

Will respect the [`parserOptions.sourceType`] from ESLint config, i.e. files parsed
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "2.0.0",
"version": "2.0.1",
"description": "Import with sanity.",
"engines": {
"node": ">=4"
Expand Down Expand Up @@ -51,20 +51,20 @@
"babel-eslint": "next",
"babel-plugin-istanbul": "^2.0.1",
"babel-preset-es2015-argon": "latest",
"babel-register": "6.9.0",
"babel-register": "6.16.3",
"chai": "^3.4.0",
"coveralls": "^2.11.4",
"cross-env": "^3.0.0",
"eslint": "3.x",
"eslint-import-resolver-node": "file:./resolvers/node",
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-module-utils": "file:./utils",
"eslint-plugin-import": "next",
"eslint-plugin-import": "2.x",
"gulp": "^3.9.0",
"gulp-babel": "6.1.2",
"istanbul": "^0.4.0",
"linklocal": "^2.6.0",
"mocha": "^2.2.1",
"mocha": "^3.1.2",
"nyc": "^8.3.0",
"redux": "^3.0.4",
"rimraf": "2.5.2",
Expand All @@ -78,7 +78,7 @@
"builtin-modules": "^1.1.1",
"contains-path": "^0.1.0",
"debug": "^2.2.0",
"doctrine": "1.3.x",
"doctrine": "1.5.0",
"eslint-import-resolver-node": "^0.2.0",
"eslint-module-utils": "^1.0.0",
"has": "^1.0.1",
Expand Down
3 changes: 1 addition & 2 deletions resolvers/node/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var resolve = require('resolve')
, path = require('path')
, assign = require('object-assign')

var log = require('debug')('eslint-plugin-import:resolver:node')

Expand All @@ -26,7 +25,7 @@ exports.resolve = function (source, file, config) {
}

function opts(file, config) {
return assign({
return Object.assign({
// more closely matches Node (#333)
extensions: ['.js', '.json'],
},
Expand Down
1 change: 0 additions & 1 deletion resolvers/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"homepage": "https://github.com/benmosher/eslint-plugin-import",
"dependencies": {
"debug": "^2.2.0",
"object-assign": "^4.0.1",
"resolve": "^1.1.6"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/.babelrc

This file was deleted.

8 changes: 7 additions & 1 deletion resolvers/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased

### Added
- Support for explicit Webpack config object in `.eslintrc.*`. ([#572], thanks [@jameslnewell])
- Added `resolve.modules` to configs for webpack2 support ([#569], thanks [@toshafed])

## 0.6.0 - 2016-09-13
### Added
Expand Down Expand Up @@ -63,6 +65,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- `interpret` configs (such as `.babel.js`).
Thanks to [@gausie] for the initial PR ([#164], ages ago! 😅) and [@jquense] for tests ([#278]).

[#572]: https://github.com/benmosher/eslint-plugin-import/pull/572
[#569]: https://github.com/benmosher/eslint-plugin-import/pull/569
[#533]: https://github.com/benmosher/eslint-plugin-import/pull/533
[#413]: https://github.com/benmosher/eslint-plugin-import/pull/413
[#377]: https://github.com/benmosher/eslint-plugin-import/pull/377
Expand All @@ -89,3 +93,5 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[@Rogeres]: https://github.com/Rogeres
[@Kovensky]: https://github.com/Kovensky
[@grahamb]: https://github.com/grahamb
[@jameslnewell]: https://github.com/jameslnewell
[@toshafed]: https://github.com/toshafed
14 changes: 14 additions & 0 deletions resolvers/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ settings:
config: 'webpack.multiple.config.js'
config-index: 1 # take the config at index 1
```

or with explicit config object:

```yaml
---
settings:
import/resolver:
webpack:
config:
resolve:
extensions:
- .js
- .jsx
```
58 changes: 36 additions & 22 deletions resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var findRoot = require('find-root')
, isAbsolute = path.isAbsolute || require('is-absolute')
, fs = require('fs')
, coreLibs = require('node-libs-browser')
, assign = require('object-assign')
, resolve = require('resolve')
, semver = require('semver')
, has = require('has')
Expand Down Expand Up @@ -52,32 +51,40 @@ exports.resolve = function (source, file, settings) {

log('Config path from settings:', configPath)

// see if we've got an absolute path
if (!configPath || !isAbsolute(configPath)) {
// if not, find ancestral package.json and use its directory as base for the path
packageDir = findRoot(path.resolve(file))
if (!packageDir) throw new Error('package not found above ' + file)
}
// see if we've got a config path, a config object, an array of config objects or a config function
if (!configPath || typeof configPath === 'string') {

// see if we've got an absolute path
if (!configPath || !isAbsolute(configPath)) {
// if not, find ancestral package.json and use its directory as base for the path
packageDir = findRoot(path.resolve(file))
if (!packageDir) throw new Error('package not found above ' + file)
}

configPath = findConfigPath(configPath, packageDir)
configPath = findConfigPath(configPath, packageDir)

log('Config path resolved to:', configPath)
if (configPath) {
webpackConfig = require(configPath)
} else {
log("No config path found relative to", file, "; using {}")
webpackConfig = {}
}

if (webpackConfig && webpackConfig.default) {
log('Using ES6 module "default" key instead of module.exports.')
webpackConfig = webpackConfig.default
}

log('Config path resolved to:', configPath)
if (configPath) {
webpackConfig = require(configPath)
} else {
log("No config path found relative to", file, "; using {}")
webpackConfig = {}
webpackConfig = configPath
configPath = null
}

if (typeof webpackConfig === 'function') {
webpackConfig = webpackConfig()
}

if (webpackConfig && webpackConfig.default) {
log('Using ES6 module "default" key instead of module.exports.')
webpackConfig = webpackConfig.default
}

if (Array.isArray(webpackConfig)) {
if (typeof configIndex !== 'undefined' && webpackConfig.length > configIndex) {
webpackConfig = webpackConfig[configIndex]
Expand Down Expand Up @@ -108,9 +115,14 @@ exports.resolve = function (source, file, settings) {

function createResolveSync(configPath, webpackConfig) {
var webpackRequire
, basedir = null

if (typeof configPath === 'string') {
basedir = path.dirname(configPath)
}

try {
var webpackFilename = resolve.sync('webpack', { basedir: path.dirname(configPath) })
var webpackFilename = resolve.sync('webpack', { basedir })
var webpackResolveOpts = { basedir: path.dirname(webpackFilename) }

webpackRequire = function (id) {
Expand Down Expand Up @@ -139,7 +151,7 @@ function createResolveSync(configPath, webpackConfig) {
function createWebpack2ResolveSync(webpackRequire, resolveConfig) {
var EnhancedResolve = webpackRequire('enhanced-resolve')

return EnhancedResolve.create.sync(assign({}, webpack2DefaultResolveConfig, resolveConfig))
return EnhancedResolve.create.sync(Object.assign({}, webpack2DefaultResolveConfig, resolveConfig))
}

/**
Expand Down Expand Up @@ -185,13 +197,15 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
new ModuleAliasPlugin(resolveConfig.alias || {}),
makeRootPlugin(ModulesInRootPlugin, 'module', resolveConfig.root),
new ModulesInDirectoriesPlugin(
'module', resolveConfig.modulesDirectories || ['web_modules', 'node_modules']
'module',
resolveConfig.modulesDirectories || resolveConfig.modules || ['web_modules', 'node_modules']
),
makeRootPlugin(ModulesInRootPlugin, 'module', resolveConfig.fallback),
new ModuleAsFilePlugin('module'),
new ModuleAsDirectoryPlugin('module'),
new DirectoryDescriptionFilePlugin(
'package.json', ['module', 'jsnext:main'].concat(resolveConfig.packageMains || webpack1DefaultMains)
'package.json',
['module', 'jsnext:main'].concat(resolveConfig.packageMains || webpack1DefaultMains)
),
new DirectoryDefaultFilePlugin(['index']),
new FileAppendPlugin(resolveConfig.extensions || ['', '.webpack.js', '.web.js', '.js']),
Expand Down
1 change: 0 additions & 1 deletion resolvers/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"is-absolute": "^0.2.3",
"lodash.get": "^3.7.0",
"node-libs-browser": "^1.0.0",
"object-assign": "^4.1.0",
"resolve": "^1.1.7",
"semver": "^5.3.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default {
alias: {
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
},
modules: [
path.join(__dirname, 'src'),
path.join(__dirname, 'fallback'),
'node_modules',
'bower_components',
],
modulesDirectories: ['node_modules', 'bower_components'],
root: path.join(__dirname, 'src'),
fallback: path.join(__dirname, 'fallback'),
Expand Down
28 changes: 28 additions & 0 deletions resolvers/webpack/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,32 @@ describe("config", function () {
}
expect(function () { resolve('foo', file, settings) }).to.throw(Error)
})

it("finds config object when config is an object", function () {
var settings = {
config: require(path.join(__dirname, 'files', 'some', 'absolute.path.webpack.config.js')),
}
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'))
})

it("finds the first config with a resolve section when config is an array of config objects", function () {
var settings = {
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),
}

expect(resolve('main-module', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'))
})

it("finds the config at option config-index when config is an array of config objects", function () {
var settings = {
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),
'config-index': 2,
}

expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'))
})

})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module.exports = {
alias: {
'foo': path.join(__dirname, 'absolutely', 'goofy', 'path', 'foo.js'),
},
modules: [
path.join(__dirname, 'src'),
'node_modules',
'bower_components',
],
modulesDirectories: ['node_modules', 'bower_components'],
root: path.join(__dirname, 'src'),
},
Expand Down
Loading

0 comments on commit db1343f

Please sign in to comment.