New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@practio/eslint-config-practio

Package Overview
Dependencies
Maintainers
13
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@practio/eslint-config-practio

Global eslint config for all Practio repos

  • 10.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
13
Weekly downloads
 
Created
Source

eslint-config-practio

Global eslint config for all Practio repos

Usage

In order to use this config in your project do the following:

Install this module:

$ npm i -D @practio/eslint-config-practio

After that create a file called .eslintrc.json in the root of the project with the following content:

{
  "extends": ["@practio/practio"]
}

Adding automatic formatting

First start by ensuring you have completed the steps in the Usage section of this readme before you continue.

Then install the modules needed for the formatting script and commit hook:

$ npm i -D husky lint-staged

Then add the following scripts to the package.json file of your project (notice that the format script is also calling a prettier:write script, see the prettier-config repo on how to add it):

{
  "scripts": {
    // ...
    "eslint:fix": "eslint --fix . || echo Unfixable errors were ignored and should be caught by the tests",
    "format": "npm run eslint:fix && npm run prettier:write"
  }
}

Install lint-staged as a dev dependency and add the following entry to the root of the package.json file:

{
  "lint-staged": {
    "*.@(js|jsx|ts|mjs)": ["eslint --fix"]
  }
}

Next install husky as a dev dependency and add a pre-commit hook by using the npx husky add command (see their docs). In the pre-commit file inside the .husky folder add the following line npx --no lint-staged.

You have now added a format script that can be executed in order to format the whole repository (for repositories that are merged with ready builds on Circle-CI, the merge script of ci-merge tries to run the script format if one is defined in package.json).

You have also added a commit hook that ensures that all files that you make changes to will be linted and auto fixed when they are staged with git.

If you need the formatting to ignore some specific folders (for example coverage, build or dist folders) then add a .prettierignore and a .eslintignore file to the root of the repository and add the globs that needs to be ignored to both files (it uses gitignore syntax).

That's it. Next time you make changes to your code, it will be formatted automatically as well.

Enable linting highliting in your editor

Most editors have extensions for eslint that allows for highlighting of linting errors while you code. It is recommnded that you install such an extention in your editor. Normally, those extensions should automatically register and use the .eslintrc.json file you added in the Usage section. You can also enable the extension "Auto fix on save" option to have most linting errors fixed automatically.

Adding mocha test for the linting

All project's should normally also include an automatted test that ensures the the linting rules are respected. To do this for Mocha tests then start by installing the following module:

$ npm i -D mocha-eslint

Then add the test file called eslint.test.js to the folder containing your mocha tests. The content of the file should be:

require('mocha-eslint')(['.']);

That's it. Now the linting will also be checked as part of your tests.

FAQs

Package last updated on 01 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc