eslint-plugin-require
v0.0.1
Published
ESLint rules for enforcing specified uses of RequireJS.
Downloads
3,885
Maintainers
Readme
eslint-plugin-require
ESLint rules for enforcing specified patterns of use of RequireJS and compatible AMD module loaders.
Why Use It
RequireJS provides great ways to manage, optimize, and asynchronously load dependencies, but it can be easy to make a few different types of mistakes when using it:
- Calling
require('dependency-name', cb)
to load a dependency, when what you meant wasrequire(['dependency-name'], cb)
.- require-array-syntax can be used to mitigate this issue by enforcing that the first argument to
require()
is always an array.
- require-array-syntax can be used to mitigate this issue by enforcing that the first argument to
- Forgetting to wrap your module in a
define()
call or accidentally wrapping it in arequire()
call instead.- require-define enforces that all files be a strict subset of AMD that always starts with a
define()
statement.
- require-define enforces that all files be a strict subset of AMD that always starts with a
- Using inner
require()
statements for things you had intended to optimize into one file as part of your build.- require-module-prefix mitigates this issue by enforcing that
require()
statements reference files with a common prefix, e.g.: "modules/". This supports a project structure wherein independently-loadable modules live in a "modules/" folder and can be optimized by the r.js loader to contain all their dependencies in one file, while still being dynamically loadable by other modules.
- require-module-prefix mitigates this issue by enforcing that
Getting Started
Documentation for each rule can be found in docs/rules.
Further Reading
- http://eslint.org/
- http://requirejs.org/