Giter VIP home page Giter VIP logo

eslint-config-kentcdodds's Introduction

eslint-config-kentcdodds

ESLint rules for all of my personal projects. Feel free to use these conventions :-)


Build Status version downloads MIT License All Contributors PRs Welcome Code of Conduct

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev eslint-config-kentcdodds

This library has a required peerDependencies listing for eslint

Usage

Then add the extends to your .eslintrc.js:

module.exports = {
  extends: 'kentcdodds',
  rules: {
    // your overrides
  },
}

Other configs

This config also exposes a few other configs that I use often and pull in as needed.

You can use them standalone:

module.exports = {
  extends: 'kentcdodds/<config-name>',
}

Or in combination with the base config (recommended)

module.exports = {
  extends: ['kentcdodds', 'kentcdodds/<config-name>'],
}

Things to know

  • All plugins needed for rules used by these configs are dependencies of this module so you don't have to install anything on your own.
  • The default config actually is composed of several configurations and you can use those individually. You can use each of these configs yourself if you want to leave my own personal style out of it.

Example of customized config

module.exports = {
  extends: ['kentcdodds/import', 'kentcdodds/jest'],
  rules: {
    /* custom rules */
  },
}

Issues

Looking to contribute? Look for the Good First Issue label.

πŸ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

See Bugs

πŸ’‘ Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a πŸ‘. This helps maintainers prioritize what to work on.

See Feature Requests

Contributors ✨

Thanks goes to these people (emoji key):


Kent C. Dodds

πŸ’» πŸ“– πŸš‡

Jonathan Haines

πŸ’»

Zack Yang

πŸ’»

Mohamed Oun

πŸ’»

Alexander Nanberg

πŸ’»

Hu Chen

πŸ’»

Weyert de Boer

πŸ’»

Marko Vujanic

πŸ’»

MichaΓ«l De Boey

πŸ’» πŸ“– πŸ”§

Justin Dorfman

πŸ“–

Nikolay Stoynov

πŸ“–

Andrew Mason

πŸ“–

Ben Monro

πŸ’»

Silviu Alexandru Avram

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

eslint-config-kentcdodds's People

Contributors

alexandernanberg avatar allcontributors[bot] avatar andrewmcodes avatar anilseervi avatar arvigeus avatar barrythepenguin avatar benmonro avatar dattaya avatar greenkeeperio-bot avatar huchenme avatar jdorfman avatar kentcdodds avatar michaeldeboey avatar mohamed3on avatar silviuaavram avatar ultrox avatar weyert avatar zack9433 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  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

eslint-config-kentcdodds's Issues

Empty list when using `extends: "eslint:recommended"`

I have a config where I use ESLint's recommended settings, but I want to list all the other rules and put them all in my config, so that I can turn them on some time later. Problem, when I extend the recommend list, (and with only just that)

module.exports = {
    extends: "eslint:recommended"
}

then I get nothing back, as all rules are then considered to be set (most of them to "off"). Is this by design?

Support ESLint 8.x

ESLint v8.0.0 is released πŸŽ‰

It would be awesome to have official ESLint 8 support. πŸ‘Š
I'm happy to help where I can of course πŸ™‚

Problems with import rules

I'm having problems with some import plugin rules, especifically all first import trown the same errors:

ESLint: Definition for rule '@typescript-eslint/no-unsafe-argument' was not found.(@typescript-eslint/no-unsafe-argument)
ESLint: Definition for rule 'import/no-import-module-exports' was not found.(import/no-import-module-exports)
ESLint: Definition for rule 'import/no-relative-packages' was not found.(import/no-relative-packages)
ESLint: Definition for rule 'react/no-unstable-nested-components' was not found.(react/no-unstable-nested-components)

If want to use this package, do I still need to install any additional plugins?

If I want to use this package, do I still need to install any additional plugins that you mentioned in your README.md doc like for accessibility checking? I know its being shipped with the package as those plugins are in dependencies of this package but just for shake of curiosity.

Thanks for the awesome work. I could not post it on twitter due to long text but I will wait for the reply :).

Allow ignoring unused vars in spread operator

ESlint supports the option ignoreRestSiblings as part of the no-unused-vars-rule. This flag will allow you to use something like { item, item2, item3, ...otherProps } and then just use otherProps while ignoring the other ones.

This would allow to drop item, item2, item3-fields from an existing project in a es6 way

Problem with import rules

I'm having problems with some import plugin rules, especifically all first import trown the same errors:

ESLint: Definition for rule '@typescript-eslint/no-unsafe-argument' was not found.(@typescript-eslint/no-unsafe-argument)
ESLint: Definition for rule 'import/no-import-module-exports' was not found.(import/no-import-module-exports)
ESLint: Definition for rule 'import/no-relative-packages' was not found.(import/no-relative-packages)
ESLint: Definition for rule 'react/no-unstable-nested-components' was not found.(react/no-unstable-nested-components)

I'm using React 17 I'm don't know if this version is causing the problems... but in all first import the problem persist.

Import @typescript-eslint rules in ts files

Hi! I am recently trying to move Downshift to Typescript. For this migration I also want to use the typescript rules defined here. However I can't figure out how to do so.

My .eslintrc.js looks like this, although I will probably revert and keep it in package.json.

module.exports = {
  settings: {
    'import/resolver': {
      node: {
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
    },
  },
  extends: require.resolve('./node_modules/kcd-scripts/eslint.js'),
  rules: {
    'react/jsx-indent': 'off',
    'react/prop-types': 'off',
    'max-lines-per-function': 'off',
    'jsx-a11y/label-has-for': 'off',
    'jsx-a11y/label-has-associated-control': 'off',
    'jsx-a11y/autocomplete-valid': 'off',
    'testing-library/prefer-user-event': 'off',
    'testing-library/no-node-access': 'off',
    'testing-library/no-container': 'off',
    'testing-library/render-result-naming-convention': 'off',
  },
  "overrides": [
    {
      files: ['cypress/**/*.js'],
      rules: {
        'testing-library/prefer-screen-queries': 'off',
        'testing-library/await-async-query': 'off'
      }
    }
  ]
}

Everything looks fine apart from the fact that the @typescript-eslint rules, defined here as overrides, are missing from my resulted config file. I don't know how to make sure they are added as well. I also tried to remove the overrides part above (thought it overrides the rest), but no.

When I use npx eslint --print-config ./.eslintrc.js I get all the rules defined in this repo, which is great, but nothing for @typescript, which is in the overrides part.

What do you think? How can I have those rules applied as well? Worth mentioning, I am importing from kcd-scripts but I am posting this question here since it's eslint config related. Thanks!

downshift-js/downshift#1268 is the PR where I experience this problem. It's the PR I'm kicking off the TS migration for Downshift.

why is webpack a dependency?

can it not be a devDependency? Thats a good 17Mb added to the bundle size, or 75% install size

From the readme it looks like it's to get other eslint plugins to work, but I'm still not sure if its definitely required

Edit: I'll assume its definitely needed an close this issue

pre-commit hook is failing

.config/husky/pre-commit: line 4: pretty-quick: command not found
husky - pre-commit hook exited with code 127 (error)

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

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

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 resolve 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 master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is 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.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry http://registry.npmjs.org/.


Good luck with your project ✨

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

Rushstack patch prevents importing the preset for extended presets

Hi! I am working on a larger eslint preset factory which imports existing presets to merge/harmonize them. The actual logic happens on a factory level (before eslint execution) and imports existing presets to merge them. Unfortunately, with the latest release of this preset our mechanics are not working anymore.

Commenting out this:

require('@rushstack/eslint-patch/modern-module-resolution')

from index.js and everything is fine again. Including this line again results into the following error:

Error during execution: Error: Failed to patch ESLint because the calling module was not recognized.
If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:
https://github.com/microsoft/rushstack/issues

I am actually not sure if there is an alternative way for solving this. Maybe splitting the actual configuration from the user entry point. How do you feel about this?

Support TypeScript linting

Now that kcd-scripts supports building TypeScript (see kentcdodds/kcd-scripts#131 & kentcdodds/kcd-scripts#133), eslint-config-kentcdodds should be able to lint TypeScript (like @KubaJastrz said):

Also, I think that kcd-scripts lint will fail on TypeScript files when using the default configuration. https://github.com/kentcdodds/eslint-config-kentcdodds should also be updated.

I wanted to first open this issue so we can discuss how we would handle it.

In my opinion we have 3 options:

  1. Add a kentcdodds/typescript config, like we already have for react, jest, ...
    This is how most other configs are doing it (see plugin:import/typescript, prettier/@typescript-eslint, ...)
    This means we need to check in some way whether react/jest/... is used, because overriding rules from those configs without using them will throw an error.
  2. Add kentcdodds/react-typescript/kentcdodds/jest-typescript/... configs that extend the normal configs and override the necessary rules
  3. Automatically check if typescript is a dependency and add rule overrides in the already existing configs

I'm in favor of 2 or 3, but I'm happy to hear your thoughts @kentcdodds. πŸ™‚

Problem with @typescript-eslint/no-unnecessary-condition

I'm using this code to validate if some hook is used inside an specific context but I obtain the following error: ESLint: Unnecessary conditional, value is always falsy.(@typescript-eslint/no-unnecessary-condition), what is the correct way to handle this, disabling the rule or is there another way?

import React from 'react'

import {AppStateContext} from '../components/containers'

export function useAppState() {
  const context = React.useContext(AppStateContext)

  if (!context) { // error comes from here
    throw new Error('useAppState must be used within the AppStateProvider')
  }

  return context
}

Support for Newer TypeScript Versions

Feature Request

Summary:

This issue is a proposal to add support for newer versions of TypeScript (e.g., 5.x)

Background:

Currently, eslint-config-kentcdodds specifies TypeScript ^4.0.0 as a peer dependency. Projects using newer TypeScript versions may encounter compatibility issues with the current version of eslint-config-kentcdodds.

Proposal:

I propose updating the peerDependencies in the package.json to include TypeScript 5.x versions. This update would allow users of eslint-config-kentcdodds to take advantage of the latest TypeScript features while ensuring compatibility and linting effectiveness.

Potential Challenges:

Ensuring that the existing rules and configurations are compatible with TypeScript 5.x.

Benefits:

  • Keeps eslint-config-kentcdodds up-to-date with the latest TypeScript developments.
  • Expands the user base by supporting projects that have upgraded to TypeScript 5.x.
  • Improves developer experience for those using the latest TypeScript features.

Suggested Implementation:

Update the peerDependencies in package.json to include "typescript": ">=4.0.0 <6.0.0" (or a more appropriate version range).

If necessary, review and update configurations and rules to ensure compatibility with TypeScript 5.x.

Looking Forward:

I am willing to help implement this feature and address any potential challenges. I look forward to hearing the community's input and guidance on this proposal.

formly - strings must use singlequote

Formly uses the backtick a lot. A few options

  1. Change formly to use single quotes
  2. Change formly to have a special rule to prefer backticks
  3. Change this config to prefer backticks

I don't think there's a rule to prefer single quotes and backticks

Separate out rules that require a transpiler

There are several rules in index.js that require a transpiler. It'd probably be better to pull those out into an es6.js which extends the index.js so index.js could be used without a transpiler...

Separate rules into logical chunks

Just like on the eslint website we should have different files for different types of rules and then the main file can combine them all. This way, for workshops especially, we can include the rules that are not stylistic so attendees don't hate it and stuff :) Here are the categories:

  • Possible Errors possible-errors.js
  • Best Practices best-practices.js
  • Stylistic Issues stylistic.js
  • ECMAScript 6 es6.js

The following sections will have to be divvied out to the other categories:

  • Strict Mode
  • Variables
  • Node.js and CommonJS

I think that the other plugin-specific rules should also be split into similar categories as needs be. I envision that looking like this:

└── ava
    β”œβ”€β”€ index.js // combines all the others
    β”œβ”€β”€ best-practices.js
    β”œβ”€β”€ stylistic.js
    └── possible-errors.js

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.