File: no-restricted-amd-modules.md

package info (click to toggle)
node-eslint-plugin-requirejs 4.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 936 kB
  • sloc: javascript: 4,676; perl: 48; makefile: 31; sh: 1
file content (102 lines) | stat: -rw-r--r-- 2,381 bytes parent folder | download | duplicates (3)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Disallow specific amd modules (no-restricted-amd-modules)

Disallowing usage of specific AMD modules can be useful if you want to limit the available methods a developer can use. For example, you can block usage of the `module-foo` module if you want to force using a more performant module named `module-bar`.

## Rule Details

This rule allows you to specify modules that you don’t want to use in your application.

## Options

The rule takes one or more strings as options: the names of restricted modules.

```json
"no-restricted-amd-modules": ["error", "module-foo", "module-bar"]
```

It can also take an object with lists of `paths` and gitignore-style `patterns` strings.

```json
"no-restricted-amd-modules": ["error", {
    "paths": ["module-foo", "module-bar"],
    "patterns": ["module-foo/private/*", "module-bar/*", "!module-bar/good"]
}]
```

You may also specify a custom message for any paths you want to restrict as follows:

```json
"no-restricted-amd-modules": ["error",
  {
    "name": "module-foo1",
    "message": "Please use module-foo2 instead."
  },
 {
    "name": "module-bar2",
    "message": "Please use module-bar2 instead."
  }
]
```

or like this:

```json
"no-restricted-amd-modules": ["error", {
  "paths": [{
    "name": "module-foo",
    "message": "Please use module-bar instead."
  }]
}]
```

The custom message will be appended to the default error message. Please note that you may not specify custom error messages for restricted patterns as a particular module may match more than one pattern.


## Examples

Examples of **incorrect** code for this rule:

```js
/*eslint no-restricted-amd-modules: ["error", "foo", "bar"]*/

define(['foo', 'bar', 'baz'], function () {
    /* ... */
});
```

```js
/*eslint no-restricted-amd-modules: ["error", {"paths": ["foo/bar"] }]*/

define(['foo/bar', 'baz'], function () {
    /* ... */
});
```

```js
/*eslint no-restricted-amd-modules: ["error", { "patterns": ["foo/bar/*"] }]*/

define(['foo/bar/baz'], function () {
    /* ... */
});
```

Examples of **correct** code for this rule:

```js
/*eslint no-restricted-amd-modules: ["error", "baz"]*/

define(['foo', 'bar'], function () {
    /* ... */
});
```

```js
/*eslint no-restricted-amd-modules: ["error", {
    "paths": ["foo"],
    "patterns": ["baz/*", "!baz/pick"]
}]*/

define(['bar', 'baz/pick'], function () {
    /* ... */
});
```