From bdec2542aebba0d50294205dab3368e36bc1cc0d Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 26 Jul 2016 21:16:46 +0200 Subject: [PATCH] Modified error message to include the module's name (fixes #453) --- CHANGELOG.md | 4 ++++ src/rules/no-nodejs-modules.js | 2 +- tests/src/rules/no-nodejs-modules.js | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d25b777..77ba668a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Modified +- Modified [`no-nodejs-modules`] error message to include the module's name ([#453], [#461]) ## [1.12.0] - 2016-07-26 ### Added @@ -269,6 +271,7 @@ for info on changes for earlier releases. [`prefer-default-export`]: ./docs/rules/prefer-default-export.md [`no-restricted-paths`]: ./docs/rules/no-restricted-paths.md +[#461]: https://github.com/benmosher/eslint-plugin-import/pull/461 [#444]: https://github.com/benmosher/eslint-plugin-import/pull/444 [#428]: https://github.com/benmosher/eslint-plugin-import/pull/428 [#395]: https://github.com/benmosher/eslint-plugin-import/pull/395 @@ -304,6 +307,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 +[#453]: https://github.com/benmosher/eslint-plugin-import/issues/453 [#441]: https://github.com/benmosher/eslint-plugin-import/issues/441 [#423]: https://github.com/benmosher/eslint-plugin-import/issues/423 [#415]: https://github.com/benmosher/eslint-plugin-import/issues/415 diff --git a/src/rules/no-nodejs-modules.js b/src/rules/no-nodejs-modules.js index 447418238..7cdb94ec9 100644 --- a/src/rules/no-nodejs-modules.js +++ b/src/rules/no-nodejs-modules.js @@ -3,7 +3,7 @@ import isStaticRequire from '../core/staticRequire' function reportIfMissing(context, node, name) { if (importType(name, context) === 'builtin') { - context.report(node, 'Do not import Node.js builtin modules') + context.report(node, 'Do not import Node.js builtin module "' + name + '"') } } diff --git a/tests/src/rules/no-nodejs-modules.js b/tests/src/rules/no-nodejs-modules.js index 51ae9b99d..826640e31 100644 --- a/tests/src/rules/no-nodejs-modules.js +++ b/tests/src/rules/no-nodejs-modules.js @@ -5,10 +5,10 @@ import { RuleTester } from 'eslint' const ruleTester = new RuleTester() , rule = require('rules/no-nodejs-modules') -const errors = [{ +const error = message => ({ ruleId: 'no-nodejs-modules', - message: 'Do not import Node.js builtin modules', -}] + message, +}) ruleTester.run('no-nodejs-modules', rule, { valid: [ @@ -30,19 +30,19 @@ ruleTester.run('no-nodejs-modules', rule, { invalid: [ test({ code: 'import path from "path"', - errors, + errors: [error('Do not import Node.js builtin module "path"')], }), test({ code: 'import fs from "fs"', - errors, + errors: [error('Do not import Node.js builtin module "fs"')], }), test({ code: 'var path = require("path")', - errors, + errors: [error('Do not import Node.js builtin module "path"')], }), test({ code: 'var fs = require("fs")', - errors, + errors: [error('Do not import Node.js builtin module "fs"')], }), ], })