Skip to content

Commit

Permalink
⚒ revive the tests of deprecated rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 5, 2019
1 parent 4b9c4d7 commit c2fa788
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/rules/no-hide-core-modules.js
Expand Up @@ -110,8 +110,10 @@ module.exports = {
),
{
"Program:exit"() {
for (const target of targets.filter(t =>
CORE_MODULES.has(t.moduleName)
for (const target of targets.filter(
t =>
CORE_MODULES.has(t.moduleName) &&
t.moduleName === t.name
)) {
const name = target.moduleName
const allowed =
Expand All @@ -123,12 +125,12 @@ module.exports = {
continue
}

const resolved = resolve.sync(name, {
basedir: dirPath,
})
const isCore = resolved === name

if (isCore) {
let resolved = ""
try {
resolved = resolve.sync(`${name}/`, {
basedir: dirPath,
})
} catch (_error) {
continue
}

Expand Down
198 changes: 198 additions & 0 deletions tests/lib/rules/no-hide-core-modules.js
@@ -0,0 +1,198 @@
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*
* @deprecated since v4.2.0
* This rule was based on an invalid assumption.
* No meaning.
*/
"use strict"

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const path = require("path")
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-hide-core-modules")

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const THIRD_PERTY = path.resolve(
__dirname,
"../../fixtures/no-hide-core-modules/thirdparty/test.js"
)
const NO_THIRD_PERTY = path.resolve(
__dirname,
"../../fixtures/no-hide-core-modules/no-thirdparty/test.js"
)
const INDIRECT_THIRD_PERTY = path.resolve(
__dirname,
"../../fixtures/no-hide-core-modules/indirect-thirdparty/test.js"
)

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const tester = new RuleTester({
parserOptions: {
ecmaVersion: 2015,
sourceType: "module",
},
globals: { require: false },
})

tester.run("no-hide-core-modules", rule, {
valid: [
"require('util')",
{
filename: NO_THIRD_PERTY,
code: "require('util')",
},
{
filename: THIRD_PERTY,
code: "require('util')",
options: [{ allow: ["util"] }],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "require('util')",
options: [{ allow: ["util"] }],
},
{
filename: THIRD_PERTY,
code: "require('util')",
options: [{ ignoreDirectDependencies: true }],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "require('util')",
options: [{ ignoreIndirectDependencies: true }],
},

"import util from 'util'",
{
filename: NO_THIRD_PERTY,
code: "import util from 'util'",
},
{
filename: THIRD_PERTY,
code: "import util from 'util'",
options: [{ allow: ["util"] }],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "import util from 'util'",
options: [{ allow: ["util"] }],
},
{
filename: THIRD_PERTY,
code: "import util from 'util'",
options: [{ ignoreDirectDependencies: true }],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "import util from 'util'",
options: [{ ignoreIndirectDependencies: true }],
},
],
invalid: [
{
filename: THIRD_PERTY,
code: "require('util')",
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: THIRD_PERTY,
code: "require('util')",
options: [{ allow: ["path"] }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: THIRD_PERTY,
code: "require('util')",
options: [{ ignoreIndirectDependencies: true }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "require('util')",
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "require('util')",
options: [{ allow: ["path"] }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "require('util')",
options: [{ ignoreDirectDependencies: true }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},

{
filename: THIRD_PERTY,
code: "import util from 'util'",
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: THIRD_PERTY,
code: "import util from 'util'",
options: [{ allow: ["path"] }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: THIRD_PERTY,
code: "import util from 'util'",
options: [{ ignoreIndirectDependencies: true }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "import util from 'util'",
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "import util from 'util'",
options: [{ allow: ["path"] }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
{
filename: INDIRECT_THIRD_PERTY,
code: "import util from 'util'",
options: [{ ignoreDirectDependencies: true }],
errors: [
"Unexpected import of third-party module 'node_modules/util/index.js'.",
],
},
],
})

0 comments on commit c2fa788

Please sign in to comment.