Skip to content

Commit c2fa788

Browse files
committed
⚒ revive the tests of deprecated rules
1 parent 4b9c4d7 commit c2fa788

File tree

4 files changed

+208
-8
lines changed

4 files changed

+208
-8
lines changed

lib/rules/no-hide-core-modules.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ module.exports = {
110110
),
111111
{
112112
"Program:exit"() {
113-
for (const target of targets.filter(t =>
114-
CORE_MODULES.has(t.moduleName)
113+
for (const target of targets.filter(
114+
t =>
115+
CORE_MODULES.has(t.moduleName) &&
116+
t.moduleName === t.name
115117
)) {
116118
const name = target.moduleName
117119
const allowed =
@@ -123,12 +125,12 @@ module.exports = {
123125
continue
124126
}
125127

126-
const resolved = resolve.sync(name, {
127-
basedir: dirPath,
128-
})
129-
const isCore = resolved === name
130-
131-
if (isCore) {
128+
let resolved = ""
129+
try {
130+
resolved = resolve.sync(`${name}/`, {
131+
basedir: dirPath,
132+
})
133+
} catch (_error) {
132134
continue
133135
}
134136

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/**
2+
* @author Toru Nagashima
3+
* @copyright 2016 Toru Nagashima. All rights reserved.
4+
* See LICENSE file in root directory for full license.
5+
*
6+
* @deprecated since v4.2.0
7+
* This rule was based on an invalid assumption.
8+
* No meaning.
9+
*/
10+
"use strict"
11+
12+
//------------------------------------------------------------------------------
13+
// Requirements
14+
//------------------------------------------------------------------------------
15+
16+
const path = require("path")
17+
const RuleTester = require("eslint").RuleTester
18+
const rule = require("../../../lib/rules/no-hide-core-modules")
19+
20+
//------------------------------------------------------------------------------
21+
// Helpers
22+
//------------------------------------------------------------------------------
23+
24+
const THIRD_PERTY = path.resolve(
25+
__dirname,
26+
"../../fixtures/no-hide-core-modules/thirdparty/test.js"
27+
)
28+
const NO_THIRD_PERTY = path.resolve(
29+
__dirname,
30+
"../../fixtures/no-hide-core-modules/no-thirdparty/test.js"
31+
)
32+
const INDIRECT_THIRD_PERTY = path.resolve(
33+
__dirname,
34+
"../../fixtures/no-hide-core-modules/indirect-thirdparty/test.js"
35+
)
36+
37+
//------------------------------------------------------------------------------
38+
// Tests
39+
//------------------------------------------------------------------------------
40+
41+
const tester = new RuleTester({
42+
parserOptions: {
43+
ecmaVersion: 2015,
44+
sourceType: "module",
45+
},
46+
globals: { require: false },
47+
})
48+
49+
tester.run("no-hide-core-modules", rule, {
50+
valid: [
51+
"require('util')",
52+
{
53+
filename: NO_THIRD_PERTY,
54+
code: "require('util')",
55+
},
56+
{
57+
filename: THIRD_PERTY,
58+
code: "require('util')",
59+
options: [{ allow: ["util"] }],
60+
},
61+
{
62+
filename: INDIRECT_THIRD_PERTY,
63+
code: "require('util')",
64+
options: [{ allow: ["util"] }],
65+
},
66+
{
67+
filename: THIRD_PERTY,
68+
code: "require('util')",
69+
options: [{ ignoreDirectDependencies: true }],
70+
},
71+
{
72+
filename: INDIRECT_THIRD_PERTY,
73+
code: "require('util')",
74+
options: [{ ignoreIndirectDependencies: true }],
75+
},
76+
77+
"import util from 'util'",
78+
{
79+
filename: NO_THIRD_PERTY,
80+
code: "import util from 'util'",
81+
},
82+
{
83+
filename: THIRD_PERTY,
84+
code: "import util from 'util'",
85+
options: [{ allow: ["util"] }],
86+
},
87+
{
88+
filename: INDIRECT_THIRD_PERTY,
89+
code: "import util from 'util'",
90+
options: [{ allow: ["util"] }],
91+
},
92+
{
93+
filename: THIRD_PERTY,
94+
code: "import util from 'util'",
95+
options: [{ ignoreDirectDependencies: true }],
96+
},
97+
{
98+
filename: INDIRECT_THIRD_PERTY,
99+
code: "import util from 'util'",
100+
options: [{ ignoreIndirectDependencies: true }],
101+
},
102+
],
103+
invalid: [
104+
{
105+
filename: THIRD_PERTY,
106+
code: "require('util')",
107+
errors: [
108+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
109+
],
110+
},
111+
{
112+
filename: THIRD_PERTY,
113+
code: "require('util')",
114+
options: [{ allow: ["path"] }],
115+
errors: [
116+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
117+
],
118+
},
119+
{
120+
filename: THIRD_PERTY,
121+
code: "require('util')",
122+
options: [{ ignoreIndirectDependencies: true }],
123+
errors: [
124+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
125+
],
126+
},
127+
{
128+
filename: INDIRECT_THIRD_PERTY,
129+
code: "require('util')",
130+
errors: [
131+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
132+
],
133+
},
134+
{
135+
filename: INDIRECT_THIRD_PERTY,
136+
code: "require('util')",
137+
options: [{ allow: ["path"] }],
138+
errors: [
139+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
140+
],
141+
},
142+
{
143+
filename: INDIRECT_THIRD_PERTY,
144+
code: "require('util')",
145+
options: [{ ignoreDirectDependencies: true }],
146+
errors: [
147+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
148+
],
149+
},
150+
151+
{
152+
filename: THIRD_PERTY,
153+
code: "import util from 'util'",
154+
errors: [
155+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
156+
],
157+
},
158+
{
159+
filename: THIRD_PERTY,
160+
code: "import util from 'util'",
161+
options: [{ allow: ["path"] }],
162+
errors: [
163+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
164+
],
165+
},
166+
{
167+
filename: THIRD_PERTY,
168+
code: "import util from 'util'",
169+
options: [{ ignoreIndirectDependencies: true }],
170+
errors: [
171+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
172+
],
173+
},
174+
{
175+
filename: INDIRECT_THIRD_PERTY,
176+
code: "import util from 'util'",
177+
errors: [
178+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
179+
],
180+
},
181+
{
182+
filename: INDIRECT_THIRD_PERTY,
183+
code: "import util from 'util'",
184+
options: [{ allow: ["path"] }],
185+
errors: [
186+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
187+
],
188+
},
189+
{
190+
filename: INDIRECT_THIRD_PERTY,
191+
code: "import util from 'util'",
192+
options: [{ ignoreDirectDependencies: true }],
193+
errors: [
194+
"Unexpected import of third-party module 'node_modules/util/index.js'.",
195+
],
196+
},
197+
],
198+
})

0 commit comments

Comments
 (0)