Giter Site home page Giter Site logo

antfu / eslint-plugin-command Goto Github PK

View Code? Open in Web Editor NEW
163.0 3.0 9.0 268 KB

Comment-as-command for one-off codemod with ESLint.

Home Page: https://eslint-plugin-command.antfu.me/

License: MIT License

TypeScript 99.31% JavaScript 0.69%
codemod eslint-plugin

eslint-plugin-command's Issues

`/// keep-sorted` for `import/export` statements

Clear and concise description of the problem

Hiya! Basically, just a way to keep import/export statements sorted (including the elements imported within them). Some of this might fit into an entirely separate ESLint rule, but I feel like especially the first example below would fit into this plugin.

Suggested solution

basic export

/// keep-sorted
export * from './bbbbbbbbbb.ts';
export * from './aaaaaaaaaaa.ts';

// ->

/// keep-sorted
export * from './aaaaaaaaaaa.ts';
export * from './bbbbbbbbbb.ts';

basic import

/// keep-sorted
import { d, c, b, a } from './bbbbbbbbbb.ts';
import * as bbb from './bbbbbbbbbbc.ts';
import { dd, cc, aa, bb } from './aaaaaaaaaaa.ts';
import * as aaa from './aaaaaaaaaaac.ts';

// everything below isnt sorted i guess? not sure of details
import ....

// ->

/// keep-sorted
import * as aaa from './aaaaaaaaaaac.ts'; // wildcard `as` imports would have more priority based on their aliased name
import * as bbb from './bbbbbbbbbbc.ts';
import { aa, bb, cc, dd } from './aaaaaaaaaaa.ts';
import { a, b, c, d } from './bbbbbbbbbb.ts';

// everything below isnt sorted i guess? not sure of details
import ....

Alternative

No response

Additional context

No response

Validations

`/// keep-sorted` for `switch` statements

Clear and concise description of the problem

Hey there, I'm back with another suggestion: /// keep-sorted for switch statements. The idea comes from this file

Suggested solution

Basic

/// keep-sorted
switch (x) {
  case "b":
    doB();
    break
  case "a":
    doA();
    break;
}

// ->

/// keep-sorted
switch (x) {
  case "a":
    doA();
    break
  case "b":
    doB();
    break;
}

Complex/weird

/// keep-sorted
switch (x) {
  case "fallback":
    falling();
  case "c":
  case "b":
    common();
    break;
  case "d":
  case "a":
    aOrD();
    break;
}

// ->

/// keep-sorted
switch (x) {
  case "a": // `a` comes before `fallback`
  case "d":
    aOrD();
    break;
  case "fallback":
    falling();
  case "b":
  case "c":
    common();
    break;
}

Alternative

No response

Additional context

No response

Validations

Hoist-regex

Clear and concise description of the problem

function foo(file) {
  /// hoist-regex customName
  return file.test(/some-regex/)
}

to

const customName = /some-regex/
function foo(file) {
  return file.test(customName)
}

Suggested solution

Alternative

Later we could support a bunch of other hoist-x commands

Additional context

No response

Validations

`/// to-promise-all`

Clear and concise description of the problem

Hey there, I started using eslint-plugin-command and it's a pure joy so far, thanks @antfu!

I'd like a new command to refactor sequential promises to a single Promise.all call to run things in parallel.

Source:

/// to-promise-all
const a = await getA();
const b = await getB();
const c = await getC();

Suggested solution

Result:

const [a, b, c] = await Promise.all([getA(), getB(), getC()]);

Alternative

There might already be an eslint rule that finds and fixes potential performance issues, but I haven't found it yet

Additional context

Maybe the reverse operation /// to-seq-await would make sense if one wants to introduce dependencies between the promises and avoid refactoring by hand:

/// to-seq-await
const [a, b, c] = await Promise.all([getA(b), getB(c), getC()]);

const c = await getC();
const b = await getB(c);
const a = await getA(a);

Validations

Interconversion between `template string` and `string`

Clear and concise description of the problem

I would like to use a command to interconvert between template string and string.

Suggested solution

Interconversion would be easy, if there are multiple strings in one line, we can specify the number or all to covert.

Alternative

No response

Additional context

No response

Validations

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.