1 | |||
2 | export const PeerDependency = { |
||
3 | X : class PeerDependencyX extends Error { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
4 | constructor(error) { |
||
5 | super(error.message); |
||
6 | this.name = 'MISSING_PEER_DEPENDENCY'; |
||
7 | this.original = error; |
||
8 | } |
||
9 | }, |
||
10 | |||
11 | load(moduleName) { |
||
12 | try { |
||
13 | // eslint-disable-next-line security/detect-non-literal-require |
||
14 | return require(moduleName); |
||
15 | } catch (error) { |
||
16 | return new this.X(error); |
||
17 | } |
||
18 | }, |
||
19 | |||
20 | check(module) { |
||
21 | if (module instanceof this.X) throw module.original; |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
22 | } |
||
23 | }; |
||
24 |