Code Monkey home page Code Monkey logo

lint-config's Introduction

lint-config

This is a repository that focuses on integrating ESLint, Stylelint, and Commitlint to set up code quality and consistency standards in your project. By implementing these tools helps you enforce proper coding styles, detect errors, and ensure clear commits in your GitHub projects.

  • Auto fix for formatting with ESlint
  • Mulit eslint config presets: JavaScript,TypeScript, Vue and React
  • Format other files : json, yaml,markdown
  • Check for syntax errors in SCSS and CSS with Stylelint
  • Standardized commit information by Commitlint

Usage

Install

pnpm add -D eslint @chansee97/xxx-config
  • @chansee97/eslint-config-basic
  • @chansee97/eslint-config-ts
  • @chansee97/eslint-config-vue
  • @chansee97/eslint-config-react
  • @chansee97/stylelint-config
  • @chansee97/commitlint-config

Config Eslint

pnpm i -D eslint

echo '{"extends": "@chansee97/eslint-config-xxx"}' > .eslintrc

add script to package.json

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

TypeScript Aware Rules

Type aware rules are enabled when a tsconfig.eslint.json is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no tsconfig.eslint.json in the project root, you can change tsconfig name by modifying ESLINT_TSCONFIG env.

// .eslintrc.js
process.env.ESLINT_TSCONFIG = 'tsconfig.json'
module.exports = {
  extends: '@chansee97/eslint-config-vue'
}

Lint Staged

If you want to apply lint and auto-fix before every commit, you can add the following to your package.json:

{
  "simple-git-hooks": {
    "pre-commit": "pnpm lint-staged"
  },
  "lint-staged": {
    "*.{js,jsx,,mjs,ts,tsx,json,,md,yml}": [
      "eslint --fix"
    ],
    "*.{css,scss,less,html}": [
      "stylelint --fix"
    ],
    "*.vue": [
      "eslint --fix",
      "stylelint --fix"
    ]
  }
}

and then

pnpm i -D lint-staged simple-git-hooks
// apply your hooks config
npx simple-git-hooks

Lint CSS, SCSS

pnpm i -D stylelint

echo '{"extends": "@chansee97/stylelint-config"}' > .stylelintrc

add script to package.json

{
  "scripts": {
    "stylelint:fix": "npx stylelint **/*.{css,scss,vue,less,html} --fix"
  }
}

Visual Studio Code

{
  "stylelint.validate": [
    // โ†“ Add "vue" language.
    "vue"
  ]
}

Lint Commit information

If you want to constrain the Commit information of the project, you need add the following to your package.json:

pnpm i -D @commitlint/cli

echo '{"extends": "@chansee97/commitlint-config"}' > .commitlintrc
{
  "simple-git-hooks": {
    "commit-msg": "npx --no-install commitlint --edit $HUSKY_GIT_PARAMS "
  }
}

Extending the config

extend your config in .eslintrc, .stylelintrc, .commitlintrc...

{
  "extends": "@chansee97/xxx-config",
  "rules": {
    // your rules...
  }
}

config alias

 settings: {
'import/resolver': {
    node: { extensions: ['.js', '.mjs'] },
    // default alias
    alias: {
      map: [
        ['~', '.'],
        ['@', './src'],
      ],
      extensions: ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'],
    },
  },
},

Thanks

This repository is modified from @antfu/eslint-config

License

MIT License

lint-config's People

Contributors

chansee97 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.