From 51095c68b857339f4b3c940ac5f81122d26847df Mon Sep 17 00:00:00 2001 From: Judith Hartmann Date: Mon, 29 Oct 2018 11:19:23 +0100 Subject: [PATCH] Fix: ignoreCase in sort-named-imports is not set to true even if config is false --- __test__/rules/sort-named-imports.spec.js | 27 +++++++++++++++++++++++ src/rules/sort-named-imports.js | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/__test__/rules/sort-named-imports.spec.js b/__test__/rules/sort-named-imports.spec.js index 8a7bdd1..86b196b 100644 --- a/__test__/rules/sort-named-imports.spec.js +++ b/__test__/rules/sort-named-imports.spec.js @@ -18,6 +18,23 @@ ruleTester.run('codebox/sort-named-imports', sortNamedImportsRule, { `, options: [{ ignoreCase: true }], }, + { + code: ` + import { a, B, c } from 'fs' + `, + options: [{ ignoreCase: true }], + }, + { + code: ` + import { a, B, c } from 'fs' + `, + }, + { + code: ` + import { B, a, c } from 'fs' + `, + options: [{ ignoreCase: false }], + }, ], invalid: [ { @@ -30,5 +47,15 @@ ruleTester.run('codebox/sort-named-imports', sortNamedImportsRule, { import { a, b, c } from 'fs' `, }, + { + code: ` + import { a, B, c } from 'fs' + `, + errors: [{ message: `Member 'B' of the import declaration should be sorted alphabetically` }], + options: [{ ignoreCase: false }], + output: ` + import { B, a, c } from 'fs' + `, + }, ], }) diff --git a/src/rules/sort-named-imports.js b/src/rules/sort-named-imports.js index 75b4698..b3081a9 100644 --- a/src/rules/sort-named-imports.js +++ b/src/rules/sort-named-imports.js @@ -26,7 +26,7 @@ module.exports = { create(context) { const sourceCode = context.getSourceCode() const config = context.options[0] || {} - const ignoreCase = config.ignoreCase || true + const ignoreCase = config.ignoreCase !== undefined ? config.ignoreCase : true; return { ImportDeclaration(node) { const importSpecifiers = node.specifiers.filter(