janpaul123 / eslint-plugin-import-order-alphabetical Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED
License: MIT License
DEPRECATED
License: MIT License
Although using imports and requires in the same file should be avoided, there are some bugs if you do.
With these ESLint rules:
{
"import/newline-after-import": "error",
"import-order-alphabetical/order": [
"error",
{
"newlines-between": "never"
}
]
}
This should be valid, but instead results in the error There should be no empty line between import groups (import-order-alphabetical/order)
on the first line:
import a from 'a'
const b = require('b')
Also, this should be valid, but instead results in the error `a` import should occur before import of `./b` (import-order-alphabetical/order)
on the require
:
import b from './b'
import c from './c'
const a = require('a')
Is there a way to ignore sorting for the grouping?
I would like to ignore sorting in the first grouping
import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { useParams } from 'react-router-dom';
maybe add something like that
'eslint-plugin-import-order-alphabetical': [
'error',
{
groups: [
['builtin', {ignoreOrder: true}],
'external', 'internal', 'index', ['sibling', 'parent']],
'newlines-between': 'always',
},
]
Having:
import PropTypes from 'prop-types';
import Button from 'custom-button';
import SearchBox from 'custom-search-box';
I would like to have them sorted:
import Button from 'custom-button';
import PropTypes from 'prop-types';
import SearchBox from 'custom-search-box';
Currently the plugin sorts like this:
import Button from 'custom-button';
import SearchBox from 'custom-search-box';
import PropTypes from 'prop-types';
In the version of eslint 7.22.0, has this bug:
AssertionError [ERR_ASSERTION]: Fix has invalid range: {
"range": [
null,
null
],
"text": "import { ListrTask } from 'listr2'\nimport fs from 'fs-extra'\n\n// const unzipBackup = (): ListrTask => ({\n// title: 'Unzip',\n// task: () => {\n// //\n// },\n// });\n//\n// export default unzipBackup;\nimport { ListrTask } from 'listr2'\nimport fs from 'fs-extra'\n\n// const unzipBackup = (): ListrTask => ({\n// title: 'Unzip',\n// task: () => {\n// //\n// },\n// });\n//\n// export default unzipBackup;\n"
}
at assertValidFix ([hidden]\node_modules\eslint\lib\linter\report-translator.js:125:9)
at normalizeFixes ([hidden]\node_modules\eslint\lib\linter\report-translator.js:200:5)
at [hidden]\node_modules\eslint\lib\linter\report-translator.js:364:49
at Object.report ([hidden]\node_modules\eslint\lib\linter\linter.js:920:41)
at fixOutOfOrder ([hidden]\node_modules\eslint-plugin-import-order-alphabetical\order.js:205:13)
at [hidden]\node_modules\eslint-plugin-import-order-alphabetical\order.js:264:5
at Array.forEach (<anonymous>)
at reportOutOfOrder ([hidden]\node_modules\eslint-plugin-import-order-alphabetical\order.js:260:14)
at makeOutOfOrderReport ([hidden]\node_modules\eslint-plugin-import-order-alphabetical\order.js:280:3)
at reportAndReset ([hidden]\node_modules\eslint-plugin-import-order-alphabetical\order.js:476:9)
Process finished with exit code -1
But with eslint 7.21.0 works perfect, I think the problem is in the fixer.
Node: 14.15.4
Yarn: 2.4.1
I am working on a react application and one of the rules I have is to keep the react import always first.
So, I would like to exclude this line from sorting.
From:
import React from 'react';
import SizeMe from 'react-sizeme';
import PropTypes from 'prop-types';
To:
import React from 'react';
import PropTypes from 'prop-types';
import SizeMe from 'react-sizeme';
One option I can think of would be a comment at the end, something like:
// eslint-disable-line
// import-order-alphabetical-ignore-line
Another option would be to be able to add a way to ignore lines in the .eslintrc rule.
I have this:
import A from './A';
import C from '../C';
import B from '../../B';
When sorting with:
"import-order-alphabetical/order": [2, {
"groups": [["builtin", "external"], ["index", "parent", "sibling"]]
}],
I get:
import B from '../../B';
import C from '../C';
import A from './A';
What I expect, it would be to be sorted:
import A from './A';
import B from '../../B';
import C from '../C';
Is there a way to make this plugin do this?
This can autofix:
const b = require('b')
const a = require('a')
But this can't:
const b = require('b')
const { a } = require('a')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.