Coder Social home page Coder Social logo

stefanobartoletti / eslint-config Goto Github PK

View Code? Open in Web Editor NEW
20.0 1.0 1.0 792 KB

My ESlint configuration, based on `@antfu/eslint-config` with personal customizations. Also includes optional rulesets for Nuxt and Tailwind.

Home Page: https://www.npmjs.com/package/@stefanobartoletti/eslint-config

License: MIT License

JavaScript 100.00%
eslint eslint-config eslintconfig

eslint-config's Introduction

npm version npm downloads License code style

My ESlint configuration, based on @antfu/eslint-config with personal customizations. Nicely integrates with Nuxt and provides optional rules for Tailwind.

Release Notes


๐ŸŒŸ Features

This is my personal ESlint configuration, based on the excellent @antfu/eslint-config. It only deviates for some minor tweaks and personal preferences, since I agree almost completely with Anthony's style choices.

This config integrates nicely with the Nuxt ESLint module, and also adds optional rules for Tailwind, by using eslint-plugin-tailwindcss

Some of the main features, inherited directly from @antfu/eslint-config:

  • Vue and TypeScript support
  • Linting for Json, Yaml, Markdown
  • Uses the easily extensible ESLint Flat config
  • Includes ESLint Stylistic to format code and enforce a preconfigured style (Prettier not required and not officially supported)
  • ... and many more (check its docs for the full list)

My own customizations and preferences:

  • (General) Force use of curly braces on control statements
  • (General) Disable antfu/top-level-function to allow arrow syntax on top level functions
  • (Vue - Optional) Set maximum allowed attributes per line on HTML elements (10 for singleline, 1 for multiline)
  • (Vue - Optional) Set block order to <template>, <script>, <style>
  • (Tailwind - Optional) Enforce best practices and consistency for Tailwind, mainly class names ordering (imported directly from eslint-plugin-tailwindcss)
  • ... and some other minor tweaks

๐Ÿ› ๏ธ Setup

Installation

pnpm i -D eslint @stefanobartoletti/eslint-config

Configuration

With "type": "module" in package.json (recommended):

Basic use

Using the default config without arguments uses the following @antfu/eslint-config options as defaults:

  • autodetects Vue
  • autodetects Typescript
  • enables ESlint Stylistic
// eslint.config.js
import { stefanobartoletti } from '@stefanobartoletti/eslint-config'

export default stefanobartoletti()

Setting options and using custom rules

It is possible to add custom rules with the following configuration.

  • The first item must contain options to be passed to @antfu/eslint-config (read more on its docs for possible options). It must always be present even if left empty.
  • From the second item going on, you can add as many custom ESlint flat config objects as you need.
// eslint.config.js
import { stefanobartoletti } from '@stefanobartoletti/eslint-config'

export default stefanobartoletti(
  // @antfu/eslint-config options, must be the first argument
  {
    stylistic: false,
  },
  // Addtionals flat configs start from here
  {
    rules: {
      curly: 'off',
    },
  },
)

Using optional Vue and Tailwind rules

This package also provides optional configuration for Vue and Tailwind. They can be used together or by themselves, and together with further custom rules.

// eslint.config.js
import { stefanobartoletti, tailwind, vue } from '@stefanobartoletti/eslint-config'

export default stefanobartoletti(
  {}, // @antfu/eslint-config options, must always be present as first item even if empty
  vue,
  tailwind,
  {
    // ESlint Flat config rule object
  },
)

Warning

Starting from v2.x, all my custom Vue-related rules must be explicitly imported with the vue key. They were previously included in the base configuration, and automatically active even when not really needed or when the Vue plugins were not active.

Integrationg with Nuxt

[!INFO] This package used to provide custom rules to be used with Nuxt, but the latest versions of the official Nuxt configs effectively made them redundand and unnecessary. Starting from v3.x, Nuxt rules were removed from this package, the recommended way to use this config is to directly integrate it with the Nuxt module.

  1. Install the ESLint module with npx nuxi module add eslint, as described in the official docs

  2. Set it to be "standalone", to prevent conflicting with @antfu/eslint-config:

// nuxt.config.ts
export default defineNuxtConfig({

  modules: [
    '@nuxt/eslint',
  ],

  eslint: {
    config: {
      standalone: false, // <-- Important to work correctly
    },
  },
})
  1. Integrate this config by prepending it to the Nuxt provided one:
// eslint.config.js
import { stefanobartoletti, tailwind, vue } from '@stefanobartoletti/eslint-config'
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt(
  // More ESlint Flat configs, appended to Nuxt's
)
  .prepend(
    stefanobartoletti(
      {}, // Antfu Options, required
      vue, // Optional, but recommended to follow this config style preferences
      tailwind, // Optional, depending on the project
    ),
  )

๐Ÿ“ VS Code Support

If you use VS Code, you should manually enable support for ESLint flat config.

Install VS Code ESLint extension.

Add the following settings to your .vscode/settings.json:

{
  // Enable the ESLint flat config support
  "eslint.experimental.useFlatConfig": true
}

For more settings, check the "VS Code support" section in antfu/eslint-config

๐Ÿค Contributing

Note

If you want to contribute you can start by reading the Contributing guidelines.

Important

I am more than happy to accept suggestions for improvement and contributions, and to try to fix issues that may come on other people specific environments, to allow this package to be used on other people's projects too.

Anyway, keep in mind that this is my personal configuration, whose main goal is to provide a shareable base to be used across my own projects, based on my preferences and supporting tools and frameworks that I personally use on a daily basis.

Unfortunately I don't have time and resources to support frameworks, tools or features that I am not currently using. ESlint Flat config is very easy to customize and if my setup does not cater to your needs, but you still want to build up antfu's, you can use this repository as a base for your own custom take on it.

๐Ÿ“ License

MIT

ยฉ 2023-present Stefano Bartoletti

eslint-config's People

Contributors

renovate[bot] avatar roonie007 avatar stefanobartoletti avatar

Stargazers

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

Watchers

 avatar

Forkers

roonie007

eslint-config's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @antfu/eslint-config ^2.23.2
  • eslint-plugin-format ^0.1.2
  • eslint-plugin-tailwindcss ^3.17.4
  • @commitlint/cli ^19.3.0
  • @commitlint/config-conventional ^19.2.2
  • @eslint/config-inspector ^0.5.2
  • @release-it/conventional-changelog ^8.0.1
  • eslint ^9.7.0
  • husky ^9.1.1
  • release-it ^17.6.0
  • eslint >=9.7.0
  • pnpm 9.6.0

  • Check this box to trigger a request for Renovate to run again on this repository

how to ignore files and folders

I'm enjoying this eslint config more and more lately, but I'm also noticing that I need to understand flat configs a bit more.

One particular aspect I'm not fully understanding is how to ignore files:

reading the official eslint docs I do see that I should write something like this to ignore two specific folder and files:

// eslint.config.js
import { nuxt, stefanobartoletti, tailwind } from '@stefanobartoletti/eslint-config'

export default stefanobartoletti(
  {},
  nuxt,
  tailwind,
  {
    rules: {
      // my rules
    },
    ignores: [
      'folder/subFolder/**', // This does NOT ignore all subsubfolders and files
      'otherFolder/*.html', // This does NOT ignore `.html` files in that folder
    ],
  },
)

but since it doesn't work I tried to pass them to antfu's config and for some reason it works:

// eslint.config.js
import { nuxt, stefanobartoletti, tailwind } from '@stefanobartoletti/eslint-config'

export default stefanobartoletti(
  {
    ignores: [
      'folder/subFolder/**', // This will ignore all subsubfolders and files
      'otherFolder/*.html', // This will ignore only `.html` files in that folder
    ],
  },
  nuxt,
  tailwind,
  {
    rules: {
      // my rules
    },
  },
)

So at this point I'm not sure if this is me not understanding or there is a bug

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.