npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eox/eslint-config

v2.0.0

Published

EOX Prettier and ESLint config for JS projects

Downloads

324

Readme

EOX ESLint & Prettier config for JS projects

About

This reusable config aims to be our default way of setting up linting and formatting for JS projects. It includes:

  • eslint dependency
  • prettier dependency
  • typescript dependency
  • recommended eslint config
  • recommended typescript-eslint
  • typescript-eslint parser
  • vue-eslint parser
  • cypress rules
  • chai friendly errors

The config also includes a minimal set of rules, defined in index.js.

Installation

npm install --save-dev @eox/eslint-config

Usage

Prettier

To run prettier and format all your files in the current folder, use

npx prettier --write .
or
npx prettier --write "**/*"

Please refer to the Prettier CLI docs for further details.

ESLint

To include ESLint in the project, create a file called eslint.config.mjs in the app root:

import eox from "@eox/eslint-config";

export default [...eox];

Finally, to run ESLint with auto-fixing, use

npx eslint --fix .

Please refer to the ESLint configuration docs and ESLint CLI docs for further details.

TypeScript

To use typescript checks, create a tsconfig.json in the project root

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    ...
  }
}

and run the check with

npx tsc

Ignoring files

not any longer -> only for prettier?

You can add a .prettierignore file to ignore certain folders or files/patterns.

E.g.:

public
dist
*.min.js
*.bundle.js

# adapt according to your project needs

For ESlint, use the ignores property in the config file. Example:

  // other config
  { ignores: ["dist"] },
  // other config

Custom configuration & rules

Both Prettier and ESLint allow for some rule customization. Please check the Prettier configuration options and the ESLint rules for an explanation of rules that could be added/modified to this file for individual projects.

BUT: please consider if this is really necessary, or if it could be included in the centralized config rather than in an individual project. Ideally, the individual projects should not use any custom rules.

Extend with plugins

Example: Cypress & Vue

// eslint.config.js
import eox from "@eox/eslint-config";
import pluginCypress from "eslint-plugin-cypress/flat";
import pluginVue from "eslint-plugin-vue";

export default [
  ...eox,
  pluginCypress.configs.recommended,
  ...pluginVue.configs["flat/recommended"],
  {
    rules: {
      // override/add rules settings here
    },
  },
];

Checking for valid code

To check if your code is valid before committing or inside a CI pipeline, use

npx prettier --check .
npx eslint .

Automation in VS Code (extension, settings)

Prettier

Although you can use prettier via command line, in a pre-commit hook or in a CI pipeline, you can also use the VS Code extension to format files (or file sections) via a handy command or even automatically (e.g. on file save) right inside your code editor.

--> Prettier - Code formatter extension

Please refer to the description about setting up and using the extension!

As a bare minimum, create a .prettierrc.json file in the app root to let the editor know prettier is used in this project

echo {} > .prettierrc.json

ESLint

As for ESLint, automatically running and fixing your code can be obtained by changing the settings in your workspace or dev container settings, e.g.:

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