Giter Club home page Giter Club logo

eslint-config's Introduction

@leedomjs/eslint-config

Inspired by @antfu/eslint-config

npm

  • Support Vue 2 & 3
  • Single quotes, no semi
  • Auto fix for formatting
  • Also lint for TypeScript, json
  • Order tailwindcss classnames
  • Only one-line of config

Usage

Install

pnpm add -D eslint @leedomjs/eslint-config

Config .eslintrc

{
  "extends": "@leedomjs"
}

Add scripts for package.json

For example:

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
  }
}

VS Code support (auto fix)

Install VS Code ESLint extension

Add the following settings to your settings.json:

{
  "editor.formatOnSave": false,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.organizeImports": false
  },

  // The following is optional.
  // It's better to put under project setting `.vscode/settings.json`
  // to avoid conflicts with working with different eslint configs.
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "vue",
    "html",
    "vue-html",
    "jsx",
    "json",
    "jsonc",
    "json5",
    "markdown",
    "yaml"
  ]
}

Lint and auto-fix before every commit

If you want to apply lint and auto-fix before every commit, you could do this:

pnpm dlx husky-init && pnpm install -D husky lint-staged

and add the following to your package.json:

{
  "scripts": {
    // This script will be added automatically when husky is installed successfully.
    "prepare": "husky install"
  },
  "lint-staged": {
    "*": "eslint --fix"
  }
}

then add the following to your pre-commit:

.husky/pre-commit

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# remove the default script
# npx test

# add this script
npx lint-staged

If your project is small-sized, and you need quickly set up hooks and forget about it, simple-git-hook will be a good choice.

pnpm install -D simple-git-hooks lint-staged

and add the following to your package.json:

{
  "simple-git-hooks": {
    "pre-commit": "npx lint-staged"
  },
  "lint-staged": {
    "*": "eslint . --fix"
  }
}

then run the CLI script to update the git hooks with the commands from the config:

# [Optional] These 2 steps can be skipped for non-husky users
git config core.hooksPath .git/hooks/
rm -rf .git/hooks

# Update ./git/hooks
npx simple-git-hooks

Tips

You can override the rules in your .eslintrc file.

{
  "extends": "@leedomjs",
  "rules": {
    // your rules...
  }
}

No framework used, just for javascript, you can also use the package @leedomjs/eslint-config-basic

// .eslintrc
{
  "extends": "@leedomjs/eslint-config-basic"
}

If you are using tailwindcss , you can also add the package @leedomjs/eslint-config-tailwindcss which depend on eslint-plugin-tailwindcss , so you don't need to add prettier-plugin-tailwindcss and prettier extra.

// .eslintrc
{
  "extends": [
    "@leedomjs/eslint-config-tailwindcss",
    ...
  ]
}

License

MIT License © 2023-present Leedom

eslint-config's People

Contributors

leedom92 avatar

Stargazers

 avatar

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.