-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
max-dependencies.js
78 lines (68 loc) · 1.83 KB
/
max-dependencies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { test } from '../utils'
import { RuleTester } from 'eslint'
const ruleTester = new RuleTester()
, rule = require('rules/max-dependencies')
ruleTester.run('max-dependencies', rule, {
valid: [
test({ code: 'import "./foo.js"' }),
test({ code: 'import "./foo.js"; import "./bar.js";',
options: [{
max: 2,
}],
}),
test({ code: 'import "./foo.js"; import "./bar.js"; const a = require("./foo.js"); const b = require("./bar.js");',
options: [{
max: 2,
}],
}),
test({ code: 'import {x, y, z} from "./foo"'}),
],
invalid: [
test({
code: 'import { x } from \'./foo\'; import { y } from \'./foo\'; import {z} from \'./bar\';',
options: [{
max: 1,
}],
errors: [
'Maximum number of dependencies (1) exceeded.',
],
}),
test({
code: 'import { x } from \'./foo\'; import { y } from \'./bar\'; import { z } from \'./baz\';',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),
test({
code: 'import { x } from \'./foo\'; require("./bar"); import { z } from \'./baz\';',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),
test({
code: 'import { x } from \'./foo\'; import { z } from \'./foo\'; require("./bar"); const path = require("path");',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),
test({
code: 'import type { x } from \'./foo\'; import type { y } from \'./bar\'',
parser: require.resolve('babel-eslint'),
options: [{
max: 1,
}],
errors: [
'Maximum number of dependencies (1) exceeded.',
],
}),
],
})