Git Product home page Git Product logo

eslint-etc's Introduction

I build stuff.

Tools and libraries mostly. Hopefully, stuff that makes development less tedious and developers more productive.

I'm on the RxJS core team and I've written a bunch of articles about RxJS and TypeScript. You can find them on my blog: ncjamieson.com

You can sponsor my work through GitHub sponsors.

And follow me on Mastodon at fosstodon.org/@cartant.

eslint-etc's People

Contributors

anweber avatar cartant avatar dependabot[bot] avatar nachovazquez avatar rafaelss95 avatar timdeschryver avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

eslint-etc's Issues

Accept `suggestions` in `fromFixture`

Currently with fromFixture we can test fixable rules really well, without all the verbosity of errors: [...], however the same isn't possible with suggestions. Not sure if it's something you'd consider, but I'd like to write something like:

fromFixture(
  stripIndent`
  export const getCount: MemoizedSelector<any, any> = (state: AppState) => state.feature,
               ~~~~~~~~ [${messageId}]`,
  {
    suggestions: [
      {
        messageId: prefixSelectorsWithSelectSuggest as MessageIds,
        output: stripIndent`
          export const selectCount: MemoizedSelector<any, any> = (state: AppState) => state.feature`,
      },
    ],
  },
),

(Note that this can be even worse when a snippet has multiple reports ๐Ÿ˜ž).

... instead of:

{
  code: stripIndent`
  export const getCount: MemoizedSelector<any, any> = (state: AppState) => state.feature`,
  errors: [
    {
      column: 14,
      endColumn: 22,
      line: 1,
      messageId: prefixSelectorsWithSelect,
      suggestions: [
        {
          messageId: prefixSelectorsWithSelectSuggest as MessageIds,
          data: {
            name: 'selectCount',
          },
          output: stripIndent`
          export const selectCount: MemoizedSelector<any, any> = (state: AppState) => state.feature`,
        },
      ],
    },
  ],
},

This might be also great in cases where we have both suggestion and fix together.

cc/ @timdeschryver

Using `output` + `suggestions` simultaneously in `fromFixture`

Consider this scenario:

fromFixture(
  stripIndents`
import type { OnRunEffects } from '@ngrx/effects'

class NotOk6 {
  @Effect(config)
  ~~~~~~~~~~~~~~~ [${noEffectDecorator}]
  effect = this.actions.pipe(
    ofType('PING'),
    mapTo(CustomActions.pong()),
  )

  @Effect({ dispatch: false })
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${noEffectDecorator} suggest 0]
  effect2 = createEffect(() => this.actions.pipe(
    ofType('PING'),
    mapTo(CustomActions.pong()),
  ), config)
}`,
      {
        output: stripIndents`bigOutput`,
        suggestions: [
          {
            messageId: noEffectDecoratorSuggest,
            output: `anotherBigOutput`,
          },
        ],
      },
    ),

In this specific rule, we can have both suggestions and output, however fromFixture doesn't seem to handle this properly. Currently, I'm receiving this:

assert.strictEqual(Array.isArray(message.suggestions), true, Error should have an array of suggestions. Instead received "${message.suggestions}" on error with message: "${message.message}");
^
AssertionError [ERR_ASSERTION]: Error should have an array of suggestions. Instead received "undefined" on error with message: "The @Effect decorator is deprecated. Use createEffect instead."

It says that suggestions is undefined, however it shouldn't be.

It's worth noting that it works if I separate in two specs: one for output and another for suggestions... so the question is: is it a bug or maybe I'm missing something here?

Ah, I also tried to change the suggest 0 to suggest or suggest 1, but nothing changed.

Accept immutable arrays within `fromFixture`

Consider this scenario:

type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule> // 'preferConcatLatestFrom'
type Options = ESLintUtils.InferOptionsTypeFromRule<typeof rule> // [{ readonly strict: boolean; }]

const valid: TSESLint.RunTests<MessageIds, Options>['valid'] = []
const invalid: TSESLint.RunTests<MessageIds, Options>['invalid'] = [
  fromFixture(``, {
    options: [{ strict: true }], // here I get the error described below
    output: ``,
  }),
]

Type 'InvalidTestCase<"preferConcatLatestFrom", { strict: boolean; }[]>' is not assignable to type 'InvalidTestCase<"preferConcatLatestFrom", Options>'.
Types of property 'options' are incompatible.
Type 'readonly { strict: boolean; }[]' is not assignable to type 'readonly [{ strict: boolean; }]'.
Target requires 1 element(s) but source may have fewer.ts(2322)

So, to fix this, I can either do options: [{ strict: true }] as const or { output: ..., options: ... } as const and so the TS is happy, however fromFixture doesn't accept readonly arrays...

I believe that it's a simple change:

- export declare function fromFixture<TMessageIds extends string, TOptions extends unknown[]>
+ export declare function fromFixture<TMessageIds extends string, TOptions extends readonly unknown[]>

and

- suggestions?: eslint.SuggestionOutput<string>[] | null | undefined;
+ suggestions?: readonly eslint.SuggestionOutput<string>[] | null | undefined;
- suggestions?: eslint.SuggestionOutput<TMessageIds>[] | null | undefined;
+ suggestions?: readonly eslint.SuggestionOutput<TMessageIds>[] | null | undefined;

Let me know if this case was clear enough to describe the issue (and I'm able to help submitting a PR if that's the case).

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.