import/order
eslint-plugin-import
Safe autofix
eslint.config.js
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/order": "error",
},
},
];import _ from 'lodash';
import path from 'path'; // `path` import should occur before import of `lodash`
// -----
var _ = require('lodash');
var path = require('path'); // `path` import should occur before import of `lodash`
// -----
var path = require('path');
import foo from './foo'; // `import` statements must be before `require` statementimport path from 'path';
import _ from 'lodash';
// -----
var path = require('path');
var _ = require('lodash');
// -----
// Allowed as ̀`babel-register` is not assigned.
require('babel-register');
var path = require('path');
// -----
// Allowed as `import` must be before `require`
import foo from './foo';
var path = require('path');Examples from the ESLint documentation.
import/order
eslint-plugin-import
import importPlugin from "eslint-plugin-import";
export default [
{
plugins: { import: importPlugin },
rules: {
"import/order": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Forbid unnecessary path segments in import and require statements.
Ensure consistent use of file extension within the import path.
Forbid a module from importing itself.
Forbid a module from importing a module with a dependency path back to itself.
Enforce a newline after import statements.
Forbid the use of extraneous packages.