Coder Social home page Coder Social logo

mskelton / eslint-plugin-sort Goto Github PK

View Code? Open in Web Editor NEW
25.0 25.0 1.0 62.8 MB

Auto-fixable sort rules for ESLint.

Home Page: https://www.npmjs.com/package/eslint-plugin-sort

License: ISC License

JavaScript 0.11% TypeScript 99.89%
eslint eslint-plugin eslint-plugin-sort fix sort sorting-imports

eslint-plugin-sort's Introduction

Hi, I'm Mark πŸ‘‹

I'm a staff software engineer working at Ramp. I love all things frontend whether that's building stunning UI components, improving accessibility and user experience, or fine-tuning the frontend build system. Developer experience is another huge passion of mine as I like to empower myself and other engineers to build excellent solutions with less friction. TypeScript, React, CSS, and Go are where you'll find me the happiest, and a little Rust sprinkled here and there doesn't hurt.

Outside of work, I'm a Wisconsin native who loves small-town life almost as much as I like snow and winter. In my free time, I like working on my house, spending time with family and friends, and playing disc golf. My life is dedicated to the service of Jesus and sharing the good news of the gospel to the ends of the earth. My hope is for men and women to find in Jesus the only true hope for this life, and the life to come.

While I am a software engineer and a total nerd, I'm a huge extrovert and love spending time with people. If you ever want to debate the usefulness of college education for professions like computer science, I will gladly oblige as I am a self-taught developer who found very little practical value in college behind getting that slip of paper they call a diploma.

πŸ”­ Recent projects

  • Veritas. A Next.js app which allows you to assert facts regarding various SQL data sources.
  • tsk. A terminal-based task list written in Go.
  • Playwright ESLint plugin. I've been adding a lot of new features and improvements lately!
  • Bytes. A new short-form post series on my website to share knowledge on a more frequent basis.

🌱 I’m currently learning

  • React 19. Been reading through the docs for many of the React canary features understanding how they can be used in the future.
  • Advanced CSS features. Not super specific, but just been doing a lot more with advanced CSS features like scroll-driven animations, anchor positioning, and lots more.

⚑ Fun facts

  • The first programming language I learned was Python which I almost never use anymore. 🐍
  • I've had many hobbies over the years including locksmithing, Rubik's cubes, Braille, and more. πŸ”
  • I play the Ukulele daily. 🎸

eslint-plugin-sort's People

Contributors

dependabot[bot] avatar mauricekleine avatar mskelton avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

mauricekleine

eslint-plugin-sort's Issues

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

feature request: Array sorting

There are many cases where hard-coded arrays must be in order but is manually enforced.

I think ESLint can be taken advantage of to automate it by opting-in via comments on the specific array:

/* eslint-enable array-order */
/* eslint array-order: ["error", "asc"] */
const array = [1, 2, 3];
/* eslint-disable array-order */

Further examples:

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Sort Enum Properties

I love this eslint plugin and how it sorts so much more than other eslint rules/plugins that I've tried.

I am using it to sort type interface properties, but it currently doesn't work on sorting enums within TypeScript. Is this something that exists or something that could be added easily?

Example enum code:

export enum MyEnum {
  z,
  b,
  a,
}

with rule that would auto-fix/give warning/error about the properties not being sorted, and turn into:

export enum MyEnum {
  a,
  b,
  z,
}

How to sort type exports?

I have an index.ts file where I export:

export { getArbitraryFunction } from "./getArbitraryFunction";
export type { GetArbitraryFunctionInput } from "./getArbitraryFunction"

but it could also look like:

export type { GetArbitraryFunctionInput } from "./getArbitraryFunction"
export { getArbitraryFunction } from "./getArbitraryFunction";

How can I make it so that the type imports/exports are always second (but are still grouped together by file)?

`sort/import` default is not good.

First of all, this package is so underrated. The sorting works. I like it.

Perhaps, the sort/import rule default was a bummer. It has butchered my imports in the worst possible way. I wanted to turn it off, but as I look at the docs, there is the group option. That one, I really like it as well. Maybe the group option should be the default?

Is it possible to add react group? Where I can put react at the top?

Support computed properties for sort/object-properties and sort/type-properties

Would it be possible to support sorting computed properties in objects and types? I would expect computed properties to be sorted not by their computed value, but just alphabetically by the code in the computed expression.

enum SomeEnum {
    foo = 'foo',
    bar = 'bar'
}

const myMap: Record<SomeEnum, string> = {
    // sort these keys?
    [SomeEnum.foo]: 'foo thing',
    [SomeEnum.bar]: 'bar thing'
}

Sort import specifiers

Sort import specifiers alphabetically. This:

import { d, a, c, b } from ''

should become

import { a, b, c, d } from ''

sort/string-unions gives false failure. --fix is not able to fix

For the string,

type ReferrerPolicy =
  "no-referrer-when-downgrade" | "no-referrer" | "origin-when-cross-origin" | "origin" | "same-origin" | "strict-origin-when-cross-origin" | "strict-origin" | "unsafe-url";

eslint outputs the error warning| sort/string-unions: String unions should be sorted alphabetically..

My configuration is "sort/string-unions": "warn". eslint fix is unable to fix the issue.

Screenshot 2023-12-11 at 10 38 15 Screenshot 2023-12-11 at 10 41 31

[sort/imports] Bug: relative paths more than one layer sorted out of order

Description

Relative paths greater than one layer deep e.g. ../../some/path imports are not sorted with other relative path imports.

Example config

"sort/imports": [
      "error",
      {
        "groups": [
          { "regex": "^react$", "order": 10 },
          { "type": "dependency", "order": 15 },
          { "type": "side-effect", "order": 20 },
          { "regex": "^@grafana", "order": 30 },
          { "regex": "^.+\\.s?css$", "order": 50 },
          { "type": "other", "order": 40 }
        ],
        "separator": "\n"
      }
    ],

Example sorted imports

import currentRules from '../../jest/data/current-rules.json'; // outside of source dir where alias does not work
import exemptions from '../../jest/data/exemptions.json';
import labels from '../../jest/data/labels.json';
import metrics from '../../jest/data/metrics.json';
import recommendations from '../../jest/data/recommendations.json';
import recommendationsConfig from '../../jest/data/recommendations-config.json';
import recommendationsVerbose from '../../jest/data/recommendations-verbose.json';
import { rest } from 'msw'; // normal dependency

import { paths } from '@/util/constants'; // path alias

Example sorted imports with single layer relative

import currentRules from '../../jest/data/current-rules.json';
import exemptions from '../../jest/data/exemptions.json';
import labels from '../../jest/data/labels.json';
import metrics from '../../jest/data/metrics.json';
import recommendations from '../../jest/data/recommendations.json';
import recommendationsVerbose from '../../jest/data/recommendations-verbose.json';
import { rest } from 'msw';

import recommendationsConfig from '../jest/data/recommendations-config.json';
import { paths } from '@/util/constants';

Expected behavior

  • Multi layer relative imports are sorted along with single layer relative imports

Sort imports

Sort imports alphabetically.

  • Accepts a list of sort groups which can be used to sort imports into multiple groups.
  • Preset groups (i.e. node module)
  • Custom regex groups

`sort/imports` side-effect group internal ordering

As far as I understand the documentation for the sort/imports rule, each group's "order" property is for ordering the groups between each other, but it has nothing to do with how each group is internally ordered.

Right now I have side effect files (CSS files) that I need to be ordered in a specific way (changing the order in which the CSS files are imported changes how the CSS cascades/overrides each other). How can I disable the internal ordering of lines within a side-effects group, while still allowing for the top-level sorting of the side-effect group as a whole?

Right now I just disable the rule for the file which obviously works, but curious if this is configurable through the rule's options.

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.