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.
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.
"requirejs/enforce-define": [2, "main.js"]
"requirejs/enforce-define": [2, ["main.js", "app.js"]]
The following pattern is considered a warning:
// main.js
require(['foo', 'bar'], function (foo, bar) {
/* ... */
});
The following pattern is not considered a warning:
// some_module.js
define(['baz'], function (baz) {
/* ... */
});
The following pattern is considered a warning:
// some_module.js
require(['foo', 'bar'], function (foo, bar) {
/* ... */
});
The following patterns are not considered warnings:
// main.js
require(['foo', 'bar'], function (foo, bar) {
/* ... */
});
// some_module.js
define(['baz'], function (baz) {
/* ... */
});
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.