Skip to content

Commit

Permalink
Add docs, update readme and changelog
Browse files Browse the repository at this point in the history
Also removed a superfluous test.
  • Loading branch information
ttmarek committed Apr 15, 2017
1 parent e2a8ccb commit 2894b49
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`no-anonymous-default-export`] rule: report anonymous default exports ([#712], thanks [@duncanbeevers]).
- Add new value to [`order`]'s `newlines-between` option to allow newlines inside import groups ([#627], [#628], thanks [@giodamelio])
- Add `count` option to the [`newline-after-import`] rule to allow configuration of number of newlines expected ([#742], thanks [@ntdb])
- Add [`no-import-module-exports`] rule: report import declarations with CommonJS exports ([#804], thanks [@kentcdodds] and [@ttmarek])

### Changed
- [`no-extraneous-dependencies`]: use `read-pkg-up` to simplify finding + loading `package.json` ([#680], thanks [@wtgtybhertgeghgtwtg])
Expand Down Expand Up @@ -383,7 +384,9 @@ for info on changes for earlier releases.
[`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md
[`unambiguous`]: ./docs/rules/unambiguous.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
[`no-import-module-exports`]: ./docs/rules/no-import-module-exports.md

[#804]: https://github.com/benmosher/eslint-plugin-import/pull/804
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
[#712]: https://github.com/benmosher/eslint-plugin-import/pull/712
[#680]: https://github.com/benmosher/eslint-plugin-import/pull/680
Expand Down Expand Up @@ -575,3 +578,5 @@ for info on changes for earlier releases.
[@duncanbeevers]: https://github.com/duncanbeevers
[@giodamelio]: https://github.com/giodamelio
[@ntdb]: https://github.com/ntdb
[@kentcdodds]: https://github.com/kentcdodds
[@ttmarek]: https://github.com/ttmarek
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Forbid unassigned imports ([`no-unassigned-import`])
* Forbid named default exports ([`no-named-default`])
* Forbid anonymous values as default exports ([`no-anonymous-default-export`])
* Forbid imports with CommonJS exports ([`no-import-module-exports`])

[`first`]: ./docs/rules/first.md
[`no-duplicates`]: ./docs/rules/no-duplicates.md
Expand All @@ -89,6 +90,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md
[`no-named-default`]: ./docs/rules/no-named-default.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
[`no-import-module-exports`]: ./docs/rules/no-import-module-exports.md

## Installation

Expand Down
72 changes: 72 additions & 0 deletions docs/rules/no-import-module-exports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# no-import-module-exports

Reports the use of import declarations with CommonJS exports in any module
except for the [main module](https://docs.npmjs.com/files/package.json#main).

If you have multiple entry points, or are using `js:next` this rule includes an
`exceptions` option which you can use to exclude those files from the rule.

## Options

#### `exceptions`
An array of globs. The rule will be omitted from any file that matches a glob in
the options array.

For example, the following setting will omit the rule in the `some-file.js` file.

```json
"import/no-import-module-exports": ["error", {
"exceptions": ['**/*/some-file.js']
}]
```

## Rule Details

### Fail

```js
import { stuff } from 'starwars'
module.exports = thing

import * as allThings from 'starwars'
exports.bar = thing

import thing from 'other-thing'
exports.foo = bar

import thing from 'starwars'
const baz = module.exports = thing
console.log(baz)
```

### Pass
Given the following package.json:

```json
{
"main": "lib/index.js",
}
```

```js
import thing from 'other-thing'
export default thing

const thing = require('thing')
module.exports = thing

const thing = require('thing')
exports.foo = bar

import thing from 'otherthing'
console.log(thing.module.exports)

/* in lib/index.js */
import foo from 'path';
module.exports = foo;

/* in some-file.js */
/* eslint import/no-import-module-exports: ["error", {"exceptions": ['**/*/some-file.js']}] */
import foo from 'path';
module.exports = foo;
```
5 changes: 2 additions & 3 deletions src/rules/no-import-module-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ module.exports = {
const isEntryPoint = entryPoint === fileName
const isIdentifier =