Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/index.js
#	src/rules/default.js
#	src/rules/extensions.js
#	src/rules/no-named-as-default.js
#	tests/src/rules/default.js
  • Loading branch information
benmosher committed Sep 24, 2016
2 parents c8dcf4d + 20079c6 commit a560d31
Show file tree
Hide file tree
Showing 67 changed files with 2,461 additions and 1,921 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [ "es2015-loose" ],
"presets": [ "es2015-argon" ],
"sourceMaps": "inline",
"env": {
"test": {
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: node_js
node_js:
# - 0.10 # testing locally only for 0.10 (nyc fails)
# - 0.12 # assume 0.12 works if 0.10 does.
- 4
- 6

Expand Down
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

## 2.0.0 - WIP
### Added
- `recommended` shared config. Roughly `errors` and `warnings` mixed together,
with some `parserOptions` in the mix. ([#402])
- `react` shared config: added `jsx: true` to `parserOptions.ecmaFeatures`.

### Breaking
- [`import/extensions` setting] defaults to `['.js']`. ([#306])
- [`import/ignore` setting] defaults to nothing, and ambiguous modules are ignored natively. This means importing from CommonJS modules will no longer be reported by [`default`], [`named`], or [`namespace`], regardless of `import/ignore`. ([#270])

### Changed
- `imports-first` is renamed to [`first`]. `imports-first` alias will continue to
exist, but may be removed in a future major release.

## [1.16.0] - 2016-09-22
### Added
Expand Down Expand Up @@ -167,6 +180,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Changed
- Rearranged rule groups in README in preparation for more style guide rules

### Removed
- support for Node 0.10, via `es6-*` ponyfills. Using native Map/Set/Symbol.

## [1.4.0] - 2016-03-25
### Added
- Resolver plugin interface v2: more explicit response format that more clearly covers the found-but-core-module case, where there is no path.
Expand Down Expand Up @@ -300,7 +316,8 @@ for info on changes for earlier releases.
[`no-named-as-default-member`]: ./docs/rules/no-named-as-default-member.md
[`no-extraneous-dependencies`]: ./docs/rules/no-extraneous-dependencies.md
[`extensions`]: ./docs/rules/extensions.md
[`imports-first`]: ./docs/rules/imports-first.md
[`first`]: ./docs/rules/first.md
[`imports-first`]: ./docs/rules/first.md
[`no-nodejs-modules`]: ./docs/rules/no-nodejs-modules.md
[`order`]: ./docs/rules/order.md
[`named`]: ./docs/rules/named.md
Expand Down Expand Up @@ -374,6 +391,7 @@ for info on changes for earlier releases.
[#423]: https://github.com/benmosher/eslint-plugin-import/issues/423
[#416]: https://github.com/benmosher/eslint-plugin-import/issues/416
[#415]: https://github.com/benmosher/eslint-plugin-import/issues/415
[#402]: https://github.com/benmosher/eslint-plugin-import/issues/402
[#386]: https://github.com/benmosher/eslint-plugin-import/issues/386
[#373]: https://github.com/benmosher/eslint-plugin-import/issues/373
[#370]: https://github.com/benmosher/eslint-plugin-import/issues/370
Expand All @@ -382,11 +400,13 @@ for info on changes for earlier releases.
[#328]: https://github.com/benmosher/eslint-plugin-import/issues/328
[#317]: https://github.com/benmosher/eslint-plugin-import/issues/317
[#313]: https://github.com/benmosher/eslint-plugin-import/issues/313
[#306]: https://github.com/benmosher/eslint-plugin-import/issues/306
[#286]: https://github.com/benmosher/eslint-plugin-import/issues/286
[#283]: https://github.com/benmosher/eslint-plugin-import/issues/283
[#281]: https://github.com/benmosher/eslint-plugin-import/issues/281
[#275]: https://github.com/benmosher/eslint-plugin-import/issues/275
[#272]: https://github.com/benmosher/eslint-plugin-import/issues/272
[#270]: https://github.com/benmosher/eslint-plugin-import/issues/270
[#267]: https://github.com/benmosher/eslint-plugin-import/issues/267
[#266]: https://github.com/benmosher/eslint-plugin-import/issues/266
[#216]: https://github.com/benmosher/eslint-plugin-import/issues/216
Expand Down
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a

**Helpful warnings:**


* Report any invalid exports, i.e. re-export of the same name ([`export`])
* Report use of exported name as identifier of default export ([`no-named-as-default`])
* Report use of exported name as property of default export ([`no-named-as-default-member`])
Expand All @@ -50,18 +51,20 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a

**Module systems:**

* Report potentially ambiguous parse goal (`script` vs. `module`) ([`unambiguous`])
* Report CommonJS `require` calls and `module.exports` or `exports.*`. ([`no-commonjs`])
* Report AMD `require` and `define` calls. ([`no-amd`])
* No Node.js builtin modules. ([`no-nodejs-modules`])

[`unambiguous`]: ./docs/rules/unambiguous.md
[`no-commonjs`]: ./docs/rules/no-commonjs.md
[`no-amd`]: ./docs/rules/no-amd.md
[`no-nodejs-modules`]: ./docs/rules/no-nodejs-modules.md


**Style guide:**

* Ensure all imports appear before other statements ([`imports-first`])
* Ensure all imports appear before other statements ([`first`])
* Report repeated import of the same module in multiple places ([`no-duplicates`])
* Report namespace imports ([`no-namespace`])
* Ensure consistent use of file extension within the import path ([`extensions`])
Expand All @@ -70,7 +73,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Prefer a default export if module exports a single name ([`prefer-default-export`])
* Limit the maximum number of dependencies a module can have. ([`max-dependencies`])

[`imports-first`]: ./docs/rules/imports-first.md
[`first`]: ./docs/rules/first.md
[`no-duplicates`]: ./docs/rules/no-duplicates.md
[`no-namespace`]: ./docs/rules/no-namespace.md
[`extensions`]: ./docs/rules/extensions.md
Expand Down Expand Up @@ -208,40 +211,31 @@ You may set the following settings in your `.eslintrc`:
A list of file extensions that will be parsed as modules and inspected for
`export`s.

This will default to `['.js']` in the next major revision of this plugin, unless
you are using the `react` shared config, in which case it is specified as `['.js', '.jsx']`.
This defaults to `['.js']`, unless you are using the `react` shared config,
in which case it is specified as `['.js', '.jsx']`.

Note that this is different from (and likely a subset of) any `import/resolver`
extensions settings, which may include `.json`, `.coffee`, etc. which will still
factor into the `no-unresolved` rule.

Also, `import/ignore` patterns will overrule this list, so `node_modules` that
end in `.js` will still be ignored by default.
Also, the following `import/ignore` patterns will overrule this list.

#### `import/ignore`

A list of regex strings that, if matched by a path, will
not report the matching module if no `export`s are found.
In practice, this means rules other than [`no-unresolved`](./docs/rules/no-unresolved.md#ignore) will not report on any
`import`s with (absolute) paths matching this pattern, _unless_ `export`s were
found when parsing. This allows you to ignore `node_modules` but still properly
lint packages that define a [`jsnext:main`] in `package.json` (Redux, D3's v4 packages, etc.).
`import`s with (absolute filesystem) paths matching this pattern.

`no-unresolved` has its own [`ignore`](./docs/rules/no-unresolved.md#ignore) setting.

**Note**: setting this explicitly will replace the default of `node_modules`, so you
may need to include it in your own list if you still want to ignore it. Example:

```yaml
settings:
import/ignore:
- node_modules # mostly CommonJS (ignored by default)
- \.coffee$ # fraught with parse errors
- \.(scss|less|css)$ # can't parse unprocessed CSS modules, either
```
[`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main

#### `import/core-modules`

An array of additional modules to consider as "core" modules--modules that should
Expand Down
12 changes: 11 additions & 1 deletion config/react.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
/**
* - adds `.jsx` as an extension
* Adds `.jsx` as an extension, and enables JSX parsing.
*
* Even if _you_ aren't using JSX (or .jsx) directly, if your dependencies
* define jsnext:main and have JSX internally, you may run into problems
* if you don't enable these settings at the top level.
*/
module.exports = {

settings: {
'import/extensions': ['.js', '.jsx'],
},

parserOptions: {
ecmaFeatures: { jsx: true },
},

}
28 changes: 28 additions & 0 deletions config/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* The basics.
* @type {Object}
*/
module.exports = {
rules: {
// analysis/correctness
'import/no-unresolved': 'error',
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',

// red flags (thus, warnings)
'import/no-named-as-default': 'warn',
'import/no-named-as-default-member': 'warn',
'import/no-duplicates': 'warn',
'import/unambiguous': 'warn',
},

// need all these for parsing dependencies (even if _your_ code doesn't need
// all of them)
parserOptions: {
sourceType: 'module',
ecmaVersion: 6,
ecmaFeatures: { experimentalObjectRestSpread: true },
},
}
12 changes: 7 additions & 5 deletions docs/rules/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export in the imported module.
For [ES7], reports if a default is named and exported but is not found in the
referenced module.

Note: for modules, the plugin will find exported names (including defaults)
Note: for packages, the plugin will find exported names
from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example. Otherwise,
the whole `node_modules` folder is ignored by default ([`import/ignore`]) as most published modules are
formatted in CommonJS, which [at time of this writing](https://github.com/benmosher/eslint-plugin-import/issues/13)
is not able to be analyzed for exports.
Redux's npm module includes this key, and thereby is lintable, for example.

A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.

[ignored]: ../README.md#importignore
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar


## Rule Details
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/imports-first.md → docs/rules/first.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# imports-first
# first

This rule reports any imports that come after non-import
statements.
Expand Down
13 changes: 8 additions & 5 deletions docs/rules/named.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ Verifies that all named imports are part of the set of named exports in the refe

For `export`, verifies that all named exports exist in the referenced module.

Note: for modules, the plugin will find exported names from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example. Otherwise,
the whole `node_modules` folder is ignored by default ([`import/ignore`]) as most published modules are
formatted in CommonJS, which [at time of this writing](https://github.com/benmosher/eslint-plugin-import/issues/13)
is not able to be analyzed for exports.
Note: for packages, the plugin will find exported names
from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example.

A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.

[ignored]: ../README.md#importignore
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar


## Rule Details
Expand Down
13 changes: 8 additions & 5 deletions docs/rules/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ Also, will report for computed references (i.e. `foo["bar"]()`).

Reports on assignment to a member of an imported namespace.

Note: for modules, the plugin will find exported names from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example. Otherwise,
the whole `node_modules` folder is ignored by default ([`import/ignore`]) as most published modules are
formatted in CommonJS, which [at time of this writing](https://github.com/benmosher/eslint-plugin-import/issues/13)
is not able to be analyzed for exports.
Note: for packages, the plugin will find exported names
from [`jsnext:main`], if present in `package.json`.
Redux's npm module includes this key, and thereby is lintable, for example.

A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.

[ignored]: ../README.md#importignore
[unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar

## Rule Details

Expand Down
54 changes: 54 additions & 0 deletions docs/rules/unambiguous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# unambiguous

Warn if a `module` could be mistakely 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
as `script` per that setting will not be reported.

This plugin uses [Unambiguous JavaScript Grammar] internally to decide whether
dependencies should be parsed as modules and searched for exports matching the
`import`ed names, so it may be beneficial to keep this rule on even if your application
will run in an explicit `module`-only environment.

## Rule Details

For files parsed as `module` by ESLint, the following are valid:

```js
import 'foo'
function x() { return 42 }
```

```js
export function x() { return 42 }
```

```js
(function x() { return 42 })()
export {} // simple way to mark side-effects-only file as 'module' without any imports/exports
```

...whereas the following file would be reported:
```js
(function x() { return 42 })()
```

## When Not To Use It

If your application environment will always know via [some other means](https://github.com/nodejs/node-eps/issues/13)
how to parse, regardless of syntax, you may not need this rule.

Remember, though, that this plugin uses this strategy internally, so if you were
to `import` from a module with no `import`s or `export`s, this plugin would not
report it as it would not be clear whether it should be considered a `script` or
a `module`.

## Further Reading

- [Unambiguous JavaScript Grammar]
- [`parserOptions.sourceType`]
- [node-eps#13](https://github.com/nodejs/node-eps/issues/13)

[`parserOptions.sourceType`]: http://eslint.org/docs/user-guide/configuring#specifying-parser-options
[Unambiguous JavaScript Grammar]: https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md#51-determining-if-source-is-an-es-module
6 changes: 3 additions & 3 deletions memo-parser/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict"

const crypto = require('crypto')
, moduleRequire = require('../lib/core/module-require').default
, hashObject = require('../lib/core/hash').hashObject
, moduleRequire = require('eslint-module-utils/module-require').default
, hashObject = require('eslint-module-utils/hash').hashObject

const cache = new Map()

Expand All @@ -22,7 +22,7 @@ exports.parse = function parse(content, options) {

const keyHash = crypto.createHash('sha256')
keyHash.update(content)
hashObject(keyHash, options)
hashObject(options, keyHash)

const key = keyHash.digest('hex')

Expand Down
Loading

0 comments on commit a560d31

Please sign in to comment.