File: enforce-define.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 (68 lines) | stat: -rw-r--r-- 1,581 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
# Require that all files be wrapped in a `define` call (enforce-define)


## Rule Details

This rule aims to enforce consistency in a project by requiring that all JavaScript files be wrapped in a call to `define`. It will warn if it encounters an expression other than `define` in the body of the program.

### Options

This rule takes one option, which can be a string representing a filename to ignore, or an array of strings, to ignore multiple filenames. This is useful to prevent this rule from warning in your app's main file, for example.

```json
    "requirejs/enforce-define": [2, "main.js"]
    "requirejs/enforce-define": [2, ["main.js", "app.js"]]
```

#### With no ignored filename(s):

The following pattern is considered a warning:

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

The following pattern is not considered a warning:

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

#### With options [2, "main.js"]:

The following pattern is considered a warning:

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

The following patterns are not considered warnings:

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

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

## When Not To Use It

If you wish you to allow files in your project that are not wrapped in a `define`, then it is safe to disable this rule.

## Further Reading

* [Define a Module](http://requirejs.org/docs/api.html#define)