noAmd (JavaScript)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noAmd - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
import/no-amd
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noAmd": "error" } } }}Description
Section titled “Description”Disallow AMD require() and define() calls.
AMD (Asynchronous Module Definition) is an older way to split code into modules. It needs a
loader library, such as RequireJS, and declares the modules a file depends on as a list of
names passed to define() or require(). Standard import and export statements work
in all modern browsers and Node.js without an extra library, and editors and bundlers can
understand them without running the code.
This rule reports calls to define() and require() that receive exactly two arguments
when the first one is an array, such as define(["a"], function (a) {}). It only reports
calls at the top level of a file, outside of functions and blocks. Calls to a define or
require function declared in your own code aren’t reported, and neither are CommonJS
calls such as require("a").
This rule is useful while moving a codebase from AMD to standard modules.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”define(["a", "b"], function (a, b) {});code-block.js:1:1 lint/nursery/noAmd ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This define() call loads modules with AMD instead of import statements.
> 1 │ define(["a", "b"], function (a, b) {});
│ ^^^^^^
2 │
ℹ AMD needs a loader library to run, while import and export statements work everywhere and can be understood by tools without running the code.
ℹ Load each module in the list with an import statement instead, such as import a from "a".
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
require(["a", "b"], function (a, b) {});code-block.js:1:1 lint/nursery/noAmd ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This require() call loads modules with AMD instead of import statements.
> 1 │ require(["a", "b"], function (a, b) {});
│ ^^^^^^^
2 │
ℹ AMD needs a loader library to run, while import and export statements work everywhere and can be understood by tools without running the code.
ℹ Load each module in the list with an import statement instead, such as import a from "a".
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
import a from "a";const b = require("b");See Also
Section titled “See Also”- If you want to disallow CommonJS
require()andmodule.exportstoo, seenoCommonJs.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.