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.
Forbid require() calls with expressions.
Prefer a default export if module exports a single name or multiple names.
Forbid import statements with CommonJS module.exports.
Forbid importing packages through relative paths.
Ensure consistent use of file extension within the import path.