From 9c98729045412c77e3b97c49aa1351b371e4e6db Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 16 Feb 2020 01:20:32 +0100 Subject: [PATCH] Make it easier to find how to ignore the rule Fixes #38. --- CHANGELOG.md | 4 ++-- README.md | 6 ++++++ examples/ignore.js | 8 ++++++++ test/__snapshots__/examples.test.js.snap | 8 ++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f26ab39..80de9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ### Version 5.0.1 (2020-01-24) -- Fixed: Side effect imports now correctly keep their original order in - Node.js <12. Thanks to Irvin Zhan (@izhan)! +- Fixed: Side effect imports now correctly keep their original order in Node.js + <12. Thanks to Irvin Zhan (@izhan)! ### Version 5.0.0 (2019-11-22) diff --git a/README.md b/README.md index 371977c..acb9276 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ forget about sorting imports! - [Is sorting imports safe?](#is-sorting-imports-safe) - [The sorting autofix causes some odd whitespace!](#the-sorting-autofix-causes-some-odd-whitespace) - [Can I use this without autofix?](#can-i-use-this-without-autofix) + - [How do I use eslint-ignore for this rule?](#how-do-i-use-eslint-ignore-for-this-rule) - [Development](#development) - [npm scripts](#npm-scripts) - [Directories](#directories) @@ -632,6 +633,11 @@ rules one by one, not realizing they could have been autofixed. Finally, not trying to make more detailed messages makes the code of this plugin _much_ easier to work with. +### How do I use eslint-ignore for this rule? + +Looking for `/* eslint-disable */` for this rule? Read all about **[ignoring +(parts of) sorting][example-ignore].** + ## Development You need [Node.js] ~12 and npm 6. diff --git a/examples/ignore.js b/examples/ignore.js index 7a5492d..4506738 100644 --- a/examples/ignore.js +++ b/examples/ignore.js @@ -14,6 +14,10 @@ separator(); import d from "d"; import c from "c"; +// Note that putting a `eslint-disable-next-line simple-import-sort/sort` +// comment in the middle of a chunk of imports WON’T WORK. It HAS to be at the +// very start! + separator(); // If you lant to both import something from a module _and_ import it for its @@ -30,3 +34,7 @@ import Other from "another"; // especially useful for long chunks of imports, where you don’t want one little // edge case disable sorting for the whole thing. Even better is to try to fix // the issue with the side effects – relying on import order is pretty brittle. + +// If all else fails, you can use this trick of inserting code between imports +// to separate chunks of imports. +separator(); diff --git a/test/__snapshots__/examples.test.js.snap b/test/__snapshots__/examples.test.js.snap index 3904648..fc8b457 100644 --- a/test/__snapshots__/examples.test.js.snap +++ b/test/__snapshots__/examples.test.js.snap @@ -139,6 +139,10 @@ separator(); import d from "d"; import c from "c"; +// Note that putting a \`eslint-disable-next-line simple-import-sort/sort\` +// comment in the middle of a chunk of imports WON’T WORK. It HAS to be at the +// very start! + separator(); // If you lant to both import something from a module _and_ import it for its @@ -157,6 +161,10 @@ import Thing from "side-effects"; // edge case disable sorting for the whole thing. Even better is to try to fix // the issue with the side effects – relying on import order is pretty brittle. +// If all else fails, you can use this trick of inserting code between imports +// to separate chunks of imports. +separator(); + `; exports[`examples markdown.md 1`] = `