File: no-assign-require.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 (35 lines) | stat: -rw-r--r-- 1,013 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
# Disallow assignment to `require` or `window.require` (no-assign-require)

RequireJS allows you to pass configuration options by assigning to global variable `require` before RequireJS is loaded. This form of passing config may not work with third-party module loaders such as [Almond](https://github.com/jrburke/almond), however.

In other cases, overwriting `require` is probably an error, and should be avoided.

## Rule Details

The following patterns are considered warnings:

```js
var require = {
    /* ... config ... */
};

window.require = {
    /* ... config ... */
}
```

The following pattern is not a warning:

```js
// Not a potential overwrite
foo.require = 'bar';
```

## When Not To Use It

If you aren't using a third-party module loader and you wish to pass configuration this way, then it is safe to disable this rule.

## Further Reading

* [RequireJS Configuration Options](http://requirejs.org/docs/api.html#config)
* [Almond Restrictions](https://github.com/jrburke/almond#restrictions)