Giter VIP home page Giter VIP logo

eslint-plugin-shopify's Introduction

eslint-plugin-shopify's People

Contributors

alexandcote avatar amrocha avatar awaselnuk avatar beefchimi avatar bouk avatar bpscott avatar brendo avatar camerongorrie avatar clauderic avatar dangreenisrael avatar davidcornu avatar dependabot-preview[bot] avatar garyking avatar gmcgibbon avatar goodforonefare avatar greenkeeper[bot] avatar ismail-syed avatar jaxee avatar jncorpron avatar kaelig avatar kvendrik avatar lemonmade avatar macabeus avatar patsissons avatar sambostock avatar texastoland avatar vhpoet avatar yanncedric 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  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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-plugin-shopify's Issues

shopify/react-initialize-state throws on valueless class properties

Fails at line 33's node.value.type check because value is undefined:

ClassProperty(node) {
if (
classInfo == null ||
getName(node.key) !== 'state' ||
node.value.type === 'Literal'
) {
return;
}

Sample crashy input:

class Foo extends React.PureComponent<ComposedProps, State> {
  state: State;

  constructor(props: ComposedProps) {
    super(props);

    this.state = {selectedSrc};
  }
}

cc @lemonmade

`rules-status`/`rules-omitted` scripts don't run

These scripts are really useful during dependency upgrades :/

yarn run rules-omitted
yarn run v1.3.2
$ eslint-index lib/config/all.js  --status omitted
/shopify/eslint-plugin-shopify/node_modules/eslint-index/node_modules/eslint/lib/config/config-file.js:158
        throw e;
        ^

Error: Cannot read config file: /shopify/eslint-plugin-shopify/lib/config/all.js
Error: Cannot find module './rules/prettier'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/shopify/eslint-plugin-shopify/lib/config/all.js:61:5)

Add more React and Enzyme rules

  • No useless wrappers (<>{stuff}{andThings}</> > <div>{stuff}{andThings}</div>)
  • React component should make every member private except React API stuff
  • Enzyme no bad features (setState, instance, etc)
  • Don't reach across component boundaries (good: ./components, ../components, components, ../OtherComponent. bad: ../OtherComponent/any-path, ./components/SomeComponent)
  • Avoid renderFoo methods being explicitly called in render() (use components instead)
  • Avoid using most raw DOM manipulation
  • Avoid the word correct in test names

Possibly add ignorePureComponents flag to react/prefer-stateless-function

@lemonmade

WDYT to adding the ignorePureComponents flag to react/prefer-stateless-function? Enabling the flag will still result in an error if you aren't actually using props etc in the component.

Unless you'd rather deter people from using it and recommend they implement scu themselves / use a hoc.

Right now, our eslint config spits out an error if you extend React.PureComponent.

Fixes for `jsx-prefer-fragment-wrappers`

Currently getting a bunch of errors on markup that we should probably whitelist.

/Users/mattseccafien/src/github.com/Shopify/web/app/sections/Products/ProductIndex/components/ImportProductModal/components/PreviewProducts/components/Table/Row.tsx
  10:5  error  replace wrapping tr with fragment shorthand  shopify/jsx-prefer-fragment-wrappers

/Users/mattseccafien/src/github.com/Shopify/web/app/sections/Products/ProductShow/components/VariantsCard/VariantsCard.tsx
  84:7   error  replace wrapping table with fragment shorthand  shopify/jsx-prefer-fragment-wrappers
  86:11  error  replace wrapping tr with fragment shorthand     shopify/jsx-prefer-fragment-wrappers

/Users/mattseccafien/src/github.com/Shopify/web/packages/@shopify/polaris-next/components/DataTable/DataTable.tsx
  102:13  error  replace wrapping thead with fragment shorthand  shopify/jsx-prefer-fragment-wrappers
  • Add other HTML elements to valid cases in tests (ie: p, tr, thead, h1, h2)
  • Modify check only for divs and spans

prefer-class-properties

I'm interested in using your prefer-class-properties rule, but don't need the other configs/rules. I think because of the way ESLint is structured, it's difficult to use eslint-plugin-shopify and enable just that rule without also having to manually turn 'off' all other things? Any ideas/recommendations?

I guess another option would be to publish just that rule separately as its own eslint plugin. I'd be happy to do that as well but wanted to check in with you guys first.

Thanks for your time!

static properties

Prefer class properties to assignment of literals to the class. (prefer-class-properties)

Static class properties allow you to set initial values for class properties, instead of setting these after the declaration of a class.

Rule Details

This rule takes one argument. If it is 'always' (default) then it warns when it finds an assignment to this in a class constructor that could instead be a class property. If set to 'never', it will warn when any class properties are found.

The following assignments are all considered warnings when using the default or explicitly setting the argument to 'always':

class Foo {
}

    Foo.bar = 'bar';
    Foo.baz = 123;
    Foo.qux = {
      foo: 'bar',
      baz: [1, 2, 3];
    };

The following are considered warnings when setting the argument to 'never':

class Foo {
  static baz = 123;
  static qux = something();
}

When Not To Use It

If you do not care how literal class members are assigned, you can safely disable this rule.

Further Reading

Rework plugins for TS/ JS world

Over the break, I found it very annoying that, in Web (a TS-mostly project), any JS file I was editing had a lesser linting experience: any rules that we turned off because TS handles them were still turned off for JS. I think we can make this better by reworking how our configs are done. We should be able to use glob patterns to have a single plugin:shopify (or similar) config that does what our esnext config does now, and provides overrides for .ts(x)? files. Similarly, we should update our ava/ mocha configs to only apply to test files (this might not be entirely possible if we don't have a common pattern, but if we ever add a Jest-specific config we could do it using the known .test.js|ts|tsx pattern).

cc/ @ismail-syed @GoodForOneFare

shopify/jsx-no-hardcoded-content not linting correctly

"shopify/jsx-no-hardcoded-content": ['error', {
        "allowStrings": false,
        "allowNumbers": false
      }]

does not lint correctly. It throws and error for all hardcoded values in JSX.

Example:
I see the following error:
9:5 error Do not use hardcoded content as the children of the div component shopify/jsx-no-hardcoded-content

And this is my code

function Preview() {
  return (
    <div className={styles.Preview}>
      <div className={styles.Content} />
    </div>
  );
}

Similarly there are many such cases where it shouldn't throw an error

False positive with strict-component-boundaries and fixtures

We have GraphQL fixtures in our project and we include these fixtures like that :
import basicFixture from './fixtures/TestAdjacentResourcesQuery/basic.json';

Because TestAdjacentResourcesQuery folder is PascalCase, the rule thinks it is a component but is not. We use PascalCase for that because the GraphQL file related to this fixture look like TestAdjacentResourcesQuery.graphql

Maybe we should exclude fixtures folder.

Cannot Find Module eslint-plugin-shopify

`npm install eslint-plugin-shopify --save-dev
npm WARN [email protected] requires a peer of typescript@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

I also see the folder inside node_modules.

However, I keep seeing:

Cannot Find Module eslint-plugin-shopify

.eslintrc is:
{ "extends": [ "plugin:shopify/esnext", "plugin:shopify/jquery", "plugin:shopify/prettier" ] }

`jsx-prefer-fragment-wrappers` returns invalid for lots of HTML markup

Consider the following example:

function Table({content, otherContent}) {
 return (
   <table>
     <tbody>
       <tr>{content}</tr>
       <td>{otherContent}</td>
     </tbody>
   </table>
  )
}

The rule currently would consider all of those tags invalid. I think we should remove all the tag checking logic to just look for divs and spans.

@lemonmade what do you think?

consistent/explicit imports to relative/local components

A common pattern found in test files. The index.ts should be reserved for exposing pieces of the component to the outside application while test files themselves should import from the individual file they are testing.

// bad
import {Button} from '..';

// good
import {Button} from '../Button';

Prettier configs override prettierrc

plugin:shopify/typescript-prettier and plugin:shopify/prettier pass Prettier config inline overriding any external config. It can be worked around but it took me a few hours to figure out why:

  prettier/prettier:
    - error
    - parser: typescript

jquery-dollar-sign-reference misidentifies the result of await

I you have an ES2016 async function that returns a jQuery object, and you assign the await result of calling that function to a variable starting with $, the check complains.

Example:

async function foo() {
  return $(document.body);
}

let $foo = await foo(); // Not allowed

Setup greenkeeper with eslint-plugin-shopify

Originally raised by @mikkoh here:

eslint-plugin-shopify has a peer dependency for eslint 3.3.x. The current version is at 3.4.x. It would be nice to have greenkeeper create Pull Requests to get updates for peer deps or locked modules. It's safe to do this... Although the way that this repo is setup as a mono package might cause issues with greenkeeper

Chris responded with this:

I'm open to doing it, but I have a somewhat workable system of just going through every few weeks, bumping the versions on all the ESLint/ plugin dependencies, and adding configuration for all new rules as I do that.

Should strict-component-boundaries check the current filename

Occasionally components need to import their sibling components

E.g. in src/components/Banner/Banner.ts: importing a Button component import Button from './Button';

Currently this does not flag up an error. Should this be considered a boundary violation to make people change to use import {Button} from '..';

//cc @cartogram

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.