@perfective/eslint-config
Version:
ESLint shareable rules configuration
32 lines • 900 B
JavaScript
export function simpleImportSortImports(internal = []) {
return {
groups: [sideEffects(), nodePrefixedModules(), unscopedPackages(), scopedPackages(internal), ...internalPackages(internal), parentImports(), relativeImports(), styleImports()].filter(group => group.length > 0)
};
}
function sideEffects() {
return ['^\\u0000'];
}
function nodePrefixedModules() {
return ['^node:'];
}
function unscopedPackages() {
return ['^[a-zA-Z]'];
}
export function scopedPackages(exclude) {
if (exclude.length === 0) {
return ['^@'];
}
return [`^(?!${exclude.join('|')})@`];
}
export function internalPackages(internal) {
return internal.map(scope => [`^${scope}`]);
}
function parentImports() {
return ['^\\.\\.(?!/?$)', '^\\.\\./?$'];
}
function relativeImports() {
return ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'];
}
function styleImports() {
return ['^.+\\.s?css$'];
}