unicorn/prefer-module
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-module": "error",
},
},
];'use strict';
// …if (foo) {
return;
}
// …const file = path.join(__dirname, 'foo.js');// (Remove the 'use strict' directive. JavaScript modules are in strict mode by default)
// …function run() {
if (foo) {
return;
}
// …
}
run();const file = path.join(import.meta.dirname, 'foo.js');Examples from the ESLint documentation.
unicorn/prefer-module
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-module": "error",
},
},
];unicorn/prefer-module
unicorn plugin · restriction
{
"rules": {
"unicorn/prefer-module": "error"
}
}correctness/noGlobalDirnameFilename
correctness · since 2.0.0
{
"linter": {
"rules": {
"correctness": {
"noGlobalDirnameFilename": "error"
}
}
}
}Prefer .at() method for index access and String#charAt().
Prefer RegExp#test() over String#match(), String#search(), and RegExp#exec().
Prefer .some(…) over .filter(…).length check and .{find,findLast,findIndex,findLastIndex}(…).
Prefer String#slice() over String#substr() and String#substring().
Enforce the style of numeric separators by correctly grouping digits.
Prefer String#trimStart() / String#trimEnd() over String#trimLeft() / String#trimRight().