You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/no-restricted-imports.md
+33-1Lines changed: 33 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,21 @@ or like this if you need to restrict only certain imports from a module:
75
75
}]
76
76
```
77
77
78
-
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 import may match more than one pattern.
78
+
or like this if you want to apply a custom message to pattern matches:
79
+
80
+
```json
81
+
"no-restricted-imports": ["error", {
82
+
"patterns": [{
83
+
"group": ["import1/private/*"],
84
+
"message": "usage of import1 private modules not allowed."
85
+
}, {
86
+
"group": ["import2/*", "!import2/good"],
87
+
"message": "import2 is deprecated, except the modules in import2/good."
88
+
}]
89
+
}]
90
+
```
91
+
92
+
The custom message will be appended to the default error message.
79
93
80
94
To restrict the use of all Node.js core imports (via https://github.com/nodejs/node/tree/master/lib):
81
95
@@ -149,6 +163,15 @@ import { DisallowedObject as AllowedObject } from "foo";
message: "Please use the default import from 'lodash' instead."
212
+
}]}]*/
213
+
214
+
importlodashfrom'lodash';
215
+
```
216
+
185
217
## When Not To Use It
186
218
187
219
Don't use this rule or don't include a module in the list for this rule if you want to be able to import a module in your project without an ESLint error or warning.
0 commit comments