From b622e1947f6fe4748883604b95c28ad09fdd3c4b Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Thu, 5 May 2016 06:42:44 -0400 Subject: [PATCH] default to all extensions valid to avoid breaking change until semver-next --- CHANGELOG.md | 10 ++++++---- README.md | 6 ++++-- src/core/ignore.js | 7 ++++++- tests/src/utils.js | 5 ++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3534fdd4de..c8a0e9f754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,14 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - [`newline-after-import`], new rule. ([#245], thanks [@singles]) - Added an `optionalDependencies` option to [`no-extraneous-dependencies`] to allow/forbid optional dependencies ([#266], thanks [@jfmengels]). - Added `newlines-between` option to [`order`] rule ([#298], thanks [@singles]) +- [`import/extensions` setting]: a whitelist of file extensions to parse as modules + and search for `export`s. If unspecified, all extensions are considered valid (for now). + In v2, this will likely default to `['.js', MODULE_EXT]`,. ([#297], to fix [#267]) ### Fixed - [`extensions`]: fallback to source path for extension enforcement if imported module is not resolved. Also, never report for builtins (i.e. `path`). ([#296]) -### Breaking -- [`import/extensions` setting]: a whitelist of file extensions to parse as modules - and search for `export`s. Defaults to `['.js']`. - ## resolvers/webpack/0.2.4 - 2016-04-29 ### Changed - automatically find webpack config with `interpret`-able extensions ([#287], thanks [@taion]) @@ -200,6 +199,8 @@ for info on changes for earlier releases. [`named`]: ./docs/rules/named.md [`newline-after-import`]: ./docs/rules/newline-after-import.md +[#298]: https://github.com/benmosher/eslint-plugin-import/pull/298 +[#297]: https://github.com/benmosher/eslint-plugin-import/pull/297 [#296]: https://github.com/benmosher/eslint-plugin-import/pull/296 [#289]: https://github.com/benmosher/eslint-plugin-import/pull/289 [#288]: https://github.com/benmosher/eslint-plugin-import/pull/288 @@ -222,6 +223,7 @@ for info on changes for earlier releases. [#286]: https://github.com/benmosher/eslint-plugin-import/issues/286 [#281]: https://github.com/benmosher/eslint-plugin-import/issues/281 [#272]: https://github.com/benmosher/eslint-plugin-import/issues/272 +[#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 [#214]: https://github.com/benmosher/eslint-plugin-import/issues/214 diff --git a/README.md b/README.md index 5eb523d0d7..08fdd148ea 100644 --- a/README.md +++ b/README.md @@ -149,8 +149,10 @@ You may set the following settings in your `.eslintrc`: #### `import/extensions` A whitelist of file extensions that will be parsed as modules and inspected for -`export`s. This defaults to `['.js']`, unless you are using the `react` shared config, -in which case it is specified as `['.js', '.jsx']`. +`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']`. 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 diff --git a/src/core/ignore.js b/src/core/ignore.js index d70a519923..50fdc76d7d 100644 --- a/src/core/ignore.js +++ b/src/core/ignore.js @@ -10,7 +10,12 @@ function validExtensions({ settings }) { // todo: add 'mjs'? lastSettings = settings - cachedSet = new Set(settings['import/extensions'] || [ '.js' ]) + // breaking: default to '.js' + // cachedSet = new Set(settings['import/extensions'] || [ '.js' ]) + cachedSet = 'import/extensions' in settings + ? new Set(settings['import/extensions']) + : { has: () => true } // the set of all elements + return cachedSet } diff --git a/tests/src/utils.js b/tests/src/utils.js index bddd9745ce..db5fed076e 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -58,6 +58,9 @@ export const SYNTAX_CASES = [ test({ code: 'export default class x {}' }), // issue #267: parser whitelist - test({ code: 'import json from "./data.json"' }), + test({ + code: 'import json from "./data.json"', + settings: { 'import/extensions': ['.js'] }, // breaking: remove for v2 + }), ]