Git Product home page Git Product logo

eslint-plugin-import-order-alphabetical's People

Contributors

janpaul123 avatar jaydenseric avatar pur3miish avatar vidaaudrey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eslint-plugin-import-order-alphabetical's Issues

Mixed import/require bugs

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')

Ignore sorting within one group

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',
      },
    ]

Sort by default export name

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';

Bug in eslint 7.22.0

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

Exclude line from sorting

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.

Sorting unclear in group

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.