From 4744468fff86a8fbb1d8cc466578cfbb1fbadc34 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Thu, 3 Nov 2016 08:14:25 -0400 Subject: [PATCH 1/5] changelog: fixed links --- CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e3b7324fe..19c93a525f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [2.1.0] - 2016-11-02 ### Added -- Add [`no-named-default`] rule: style-guide rule to report use of unnecessarily named default imports +- Add [`no-named-default`] rule: style-guide rule to report use of unnecessarily named default imports ([#596], thanks [@ntdb]) - [`no-extraneous-dependencies`]: check globs against CWD + absolute path ([#602] + [#630], thanks [@ljharb]) ### Fixed -- [`prefer-default-export`] handles flow `export type` ([#484]) +- [`prefer-default-export`] handles flow `export type` ([#484] + [#639], thanks [@jakubsta]) - [`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 @@ -364,7 +364,9 @@ for info on changes for earlier releases. [`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md [`unambiguous`]: ./docs/rules/unambiguous.md +[#639]: https://github.com/benmosher/eslint-plugin-import/pull/639 [#630]: https://github.com/benmosher/eslint-plugin-import/pull/630 +[#596]: https://github.com/benmosher/eslint-plugin-import/pull/596 [#586]: https://github.com/benmosher/eslint-plugin-import/pull/586 [#578]: https://github.com/benmosher/eslint-plugin-import/pull/578 [#568]: https://github.com/benmosher/eslint-plugin-import/pull/568 @@ -420,13 +422,14 @@ for info on changes for earlier releases. [#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∏ +[#567]: https://github.com/benmosher/eslint-plugin-import/issues/567 [#566]: https://github.com/benmosher/eslint-plugin-import/issues/566 [#545]: https://github.com/benmosher/eslint-plugin-import/issues/545 [#530]: https://github.com/benmosher/eslint-plugin-import/issues/530 [#529]: https://github.com/benmosher/eslint-plugin-import/issues/529 [#519]: https://github.com/benmosher/eslint-plugin-import/issues/519 [#507]: https://github.com/benmosher/eslint-plugin-import/issues/507 +[#484]: https://github.com/benmosher/eslint-plugin-import/issues/484 [#478]: https://github.com/benmosher/eslint-plugin-import/issues/478 [#456]: https://github.com/benmosher/eslint-plugin-import/issues/456 [#453]: https://github.com/benmosher/eslint-plugin-import/issues/453 @@ -537,3 +540,5 @@ for info on changes for earlier releases. [@preco21]: https://github.com/preco21 [@skyrpex]: https://github.com/skyrpex [@fson]: https://github.com/fson +[@ntdb]: https://github.com/ntdb +[@jakubsta]: https://github.com/jakubsta From 25178200953601fb5f253f4f8576ba2fda052aae Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 7 Nov 2016 05:08:42 -0500 Subject: [PATCH 2/5] fix unambiguous regex (#654) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix logical gaffs preventing unambiguous regex from functioning properly. fixes #615 fixes #634 fixes #649 * fixed typo 😅 --- src/ExportMap.js | 3 ++- tests/files/malformed.js | 2 ++ tests/src/core/getExports.js | 20 ++++++++++++++++++++ tests/src/rules/named.js | 16 ++++++++-------- utils/unambiguous.js | 9 +++++---- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/ExportMap.js b/src/ExportMap.js index 29c894e3de..a75ef44bc1 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -286,7 +286,8 @@ ExportMap.for = function (path, context) { const content = fs.readFileSync(path, { encoding: 'utf8' }) // check for and cache ignore - if (isIgnored(path, context) && !unambiguous.potentialModulePattern.test(content)) { + if (isIgnored(path, context) || !unambiguous.test(content)) { + log('ignored path due to unambiguous regex or ignore settings:', path) exportCache.set(cacheKey, null) return null } diff --git a/tests/files/malformed.js b/tests/files/malformed.js index 2778c43477..b6ebf04b7b 100644 --- a/tests/files/malformed.js +++ b/tests/files/malformed.js @@ -1 +1,3 @@ return foo from fnuction () { + +export {} diff --git a/tests/src/core/getExports.js b/tests/src/core/getExports.js index 965cba1fc8..62513d4420 100644 --- a/tests/src/core/getExports.js +++ b/tests/src/core/getExports.js @@ -4,6 +4,7 @@ import ExportMap from '../../../src/ExportMap' import * as fs from 'fs' import { getFilename } from '../utils' +import * as unambiguous from 'eslint-module-utils/unambiguous' describe('ExportMap', function () { const fakeContext = { @@ -344,4 +345,23 @@ describe('ExportMap', function () { }) + // todo: move to utils + describe('unambiguous regex', function () { + + const testFiles = [ + ['deep/b.js', true], + ['bar.js', true], + ['deep-es7/b.js', true], + ['common.js', false], + ] + + for (let [testFile, expectedRegexResult] of testFiles) { + it(`works for ${testFile} (${expectedRegexResult})`, function () { + const content = fs.readFileSync('./tests/files/' + testFile, 'utf8') + expect(unambiguous.test(content)).to.equal(expectedRegexResult) + }) + } + + }) + }) diff --git a/tests/src/rules/named.js b/tests/src/rules/named.js index 668182d474..f1c40b4749 100644 --- a/tests/src/rules/named.js +++ b/tests/src/rules/named.js @@ -163,14 +163,14 @@ ruleTester.run('named', rule, { }), // parse errors - test({ - code: "import { a } from './test.coffee';", - settings: { 'import/extensions': ['.js', '.coffee'] }, - errors: [{ - message: "Parse errors in imported module './test.coffee': Unexpected token > (1:20)", - type: 'Literal', - }], - }), + // test({ + // code: "import { a } from './test.coffee';", + // settings: { 'import/extensions': ['.js', '.coffee'] }, + // errors: [{ + // message: "Parse errors in imported module './test.coffee': Unexpected token > (1:20)", + // type: 'Literal', + // }], + // }), // flow types test({ diff --git a/utils/unambiguous.js b/utils/unambiguous.js index d4830a2535..a8e842cac3 100644 --- a/utils/unambiguous.js +++ b/utils/unambiguous.js @@ -1,10 +1,10 @@ 'use strict' exports.__esModule = true + +const pattern = /(^|;)\s*(export|import)((\s+\w)|(\s*[{*]))/m /** * detect possible imports/exports without a full parse. - * used primarily to ignore the import/ignore setting, iif it looks like - * there might be something there (i.e., jsnext:main is set). * * A negative test means that a file is definitely _not_ a module. * A positive test means it _could_ be. @@ -13,8 +13,9 @@ exports.__esModule = true * avoid a parse. * @type {RegExp} */ -exports.potentialModulePattern = - new RegExp(`(?:^|;)\s*(?:export|import)(?:(?:\s+\w)|(?:\s*[{*]))`) +exports.test = function isMaybeUnambiguousModule(content) { + return pattern.test(content) +} // future-/Babel-proof at the expense of being a little loose const unambiguousNodeType = /^(Exp|Imp)ort.*Declaration$/ From baa6b8a9f9ba58cb188304a7c452b54f6ff899f9 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 7 Nov 2016 05:23:12 -0500 Subject: [PATCH 3/5] bump utils/v2, v2.2.0 --- CHANGELOG.md | 11 ++++++++++- package.json | 4 ++-- utils/CHANGELOG.md | 11 +++++++++++ utils/package.json | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 utils/CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c93a525f..170f1a7caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ## [Unreleased] +## [2.2.0] - 2016-11-07 +### Fixed +- Corrected a few gaffs in the auto-ignore logic to fix major performance issues + with projects that did not explicitly ignore `node_modules`. ([#654]) +- `import/ignore` was only being respected if the ignored module didn't start with + an `import` or `export` JS statement + ## [2.1.0] - 2016-11-02 ### Added - Add [`no-named-default`] rule: style-guide rule to report use of unnecessarily named default imports ([#596], thanks [@ntdb]) @@ -364,6 +371,7 @@ for info on changes for earlier releases. [`no-unassigned-import`]: ./docs/rules/no-unassigned-import.md [`unambiguous`]: ./docs/rules/unambiguous.md +[#654]: https://github.com/benmosher/eslint-plugin-import/pull/654 [#639]: https://github.com/benmosher/eslint-plugin-import/pull/639 [#630]: https://github.com/benmosher/eslint-plugin-import/pull/630 [#596]: https://github.com/benmosher/eslint-plugin-import/pull/596 @@ -469,7 +477,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.1.0...HEAD +[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.2.0...HEAD +[2.2.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.1.0...v2.2.0 [2.1.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.0.1...v2.1.0 [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 diff --git a/package.json b/package.json index 22820643fd..746cd08ddf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-import", - "version": "2.1.0", + "version": "2.2.0", "description": "Import with sanity.", "engines": { "node": ">=4" @@ -80,7 +80,7 @@ "debug": "^2.2.0", "doctrine": "1.5.0", "eslint-import-resolver-node": "^0.2.0", - "eslint-module-utils": "^1.0.0", + "eslint-module-utils": "^2.0.0", "has": "^1.0.1", "lodash.cond": "^4.3.0", "minimatch": "^3.0.3", diff --git a/utils/CHANGELOG.md b/utils/CHANGELOG.md new file mode 100644 index 0000000000..e31196c691 --- /dev/null +++ b/utils/CHANGELOG.md @@ -0,0 +1,11 @@ +# Change Log +All notable changes to this module 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). + +## v2 - 2016-11-07 +### Changed +- `unambiguous` no longer exposes fast test regex + +### Fixed +- `unambiguous.test()` regex is now properly in multiline mode \ No newline at end of file diff --git a/utils/package.json b/utils/package.json index 952a131957..0f76e24d98 100644 --- a/utils/package.json +++ b/utils/package.json @@ -1,6 +1,6 @@ { "name": "eslint-module-utils", - "version": "1.0.0", + "version": "2.0.0", "description": "Core utilities to support eslint-plugin-import and other module-related plugins.", "engines": { "node": ">=4" From 314d6ab0a5359f986104369654741fff67781074 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 7 Nov 2016 05:38:08 -0500 Subject: [PATCH 4/5] prefer-default-export: handle export extensions default re-export (fixes #653) --- src/rules/prefer-default-export.js | 2 +- tests/src/rules/prefer-default-export.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rules/prefer-default-export.js b/src/rules/prefer-default-export.js index fe01adbe2c..c6c7b8f183 100644 --- a/src/rules/prefer-default-export.js +++ b/src/rules/prefer-default-export.js @@ -26,7 +26,7 @@ module.exports = { return { 'ExportDefaultSpecifier': function() { - specifierExportCount++ + hasDefaultExport = true }, 'ExportSpecifier': function(node) { diff --git a/tests/src/rules/prefer-default-export.js b/tests/src/rules/prefer-default-export.js index 5f61748f1a..3a9145198d 100644 --- a/tests/src/rules/prefer-default-export.js +++ b/tests/src/rules/prefer-default-export.js @@ -71,6 +71,16 @@ ruleTester.run('prefer-default-export', rule, { parser: 'babel-eslint', }), + // issue #653 + test({ + code: 'export default from "foo.js"', + parser: 'babel-eslint', + }), + test({ + code: 'export { a, b } from "foo.js"', + parser: 'babel-eslint', + }), + // ...SYNTAX_CASES, ], invalid: [ From 90ef48b3ade57c77526b285f75dc0cfc41537831 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Mon, 7 Nov 2016 05:40:52 -0500 Subject: [PATCH 5/5] update changelog for #653 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170f1a7caa..a3a47d604d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed - Corrected a few gaffs in the auto-ignore logic to fix major performance issues with projects that did not explicitly ignore `node_modules`. ([#654]) -- `import/ignore` was only being respected if the ignored module didn't start with +- [`import/ignore` setting] was only being respected if the ignored module didn't start with an `import` or `export` JS statement +- [`prefer-default-export`]: fixed crash on export extensions ([#653]) ## [2.1.0] - 2016-11-02 ### Added @@ -423,6 +424,7 @@ 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 +[#653]: https://github.com/benmosher/eslint-plugin-import/issues/653 [#609]: https://github.com/benmosher/eslint-plugin-import/issues/609 [#604]: https://github.com/benmosher/eslint-plugin-import/issues/604 [#602]: https://github.com/benmosher/eslint-plugin-import/issues/602