From 368239476577ce6f87c09368757aa3d6e433f601 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 | 2 ++ src/rules/no-nodejs-modules.js | 2 +- tests/src/rules/no-nodejs-modules.js | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d25b7775..7762642faa 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]) ## [1.12.0] - 2016-07-26 ### Added diff --git a/src/rules/no-nodejs-modules.js b/src/rules/no-nodejs-modules.js index 4474182381..7cdb94ec9c 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 51ae9b99db..826640e317 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"')], }), ], })