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

@smartrecruiters/eslint-config

v5.0.2

Published

SmartRecruiters' ESlint rules and config

Downloads

20

Readme

@smartrecruiters/eslint-config

NPM Version NPM Downloads Node.js Version Licence Build

SmartRecruiters’ ESLint rules and configs.

Linting code in your module

ESLint compatibility

Current version is designed to work with eslint@^6.

Install eslint & @smartrecruiters/eslint-config

Install the latest eslint and @smartrecruiters/eslint-config as devDependency (-D) in your project:

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

Configure eslint in your project

In root directory of your project, create .eslintrc.yaml with following content:

extends: '@smartrecruiters/eslint-config/node/main'

or, when you use node.js v10

extends: '@smartrecruiters/eslint-config/node/10/main'

Additionally, if your project uses mocha, you may override main config and use eslint config prepared for mocha test. To do it, go to your test directory and create .eslintrc.yaml with following content:

extends: '@smartrecruiters/eslint-config/node/mocha'

or, when you use node.js v10

extends: '@smartrecruiters/eslint-config/node/10/mocha'

Update script section in your package.json:

{
  "scripts": {
    "lint": "eslint ."
  }
}

Run linter

To run linter, just type:

$ npm run lint

Hints

When you first apply linting in your legacy project, you may find many violations. Don't worry, there are some easy ways to handle this:

Automatic fix

Many rules have ability to fix your code. After you configured eslint in your project in a way described above, just run:

npm run lint -- --fix

It is done in such way because if you want to pass params into your custom npm script, you need to do that after --, so in fact what this command does is:

node_modules/.bin/eslint . --fix

Disable unwanted rule

You can easily override eslint configuration. For example, if you really want to use console.log function, you can globally disable no-console rule by changing .eslintrc.yaml:

extends: '@smartrecruiters/eslint-config/node/main'
rules:
  no-console: off

or disable this rule in a particular file or in a part of it: Disabling Rules with Inline Comments

Change rule violation from error to warning

Similarly, if you really want to use console.log, but you also want to be somehow warned about it's usage, you can change no-console rule violations severity from error to warning by changing .eslintrc.yaml:

extends: '@smartrecruiters/eslint-config/node/main'
rules:
  no-console: warn

or you can change severity of rule in a particular file: Configuring Rules

Limit warnings

And if you decide to change some errors to warnings, you can limit possible warning count to make sure no more lint violations are introduced:

npm run lint -- --max-warnings Int

where Int is a number of maximum number of warnings allowed.

Same, what this command does is actually:

node_modules/.bin/eslint . --max-warnings Int

Ignore specific files and directories

Use .eslintignore file to disable eslint in files and directories: Ignoring Files and Directories

Configuration for Intellij IDEA

It is very handy to have enabled automatic linting in your IDE:

  1. Intellij IDEA -> Preferences
  2. Languages & Frameworks -> JavaScript -> Code Quality Tools -> ESLint
  3. Tick Enable
  4. Specify ESLint package: <path_to_your_project>/node_modules/eslint
  5. Tick Automatic search

Available configurations

smartrecruiters/node/main

Prepared for your node.js code. It is based on built-in eslint config eslint-recommended. But it also has following rules enabled (see reference section for description of each rule):

smartrecruiters/node/mocha

Based on '@smartrecruiters/eslint-config/node/main', but it is prepared for mocha & chai env. If you have globals configured for your mocha test similarly:

const chai = require('chai')
chai.use(require('chai-as-promised'))
const sinon = require('sinon')

global.sinon = sinon
global.chai = chai
global.expect = chai.expect
global.should = chai.should()
global.assert = chai.assert

Then you can write tests without requiring chai in each file. This will look like using undefined variables, so this eslint configuration speficies sinon, chai, expect,should and assert as allowed global variables.

It also disables no-unused-expressions rule, because e.g. writing assertions with expect may end up with:

expect(aVirginOver20).to.exists

Which of course from technical point of view is an unused expression.

Contributing

Please see our Code of conduct and Contributing guidelines

References

  • http://eslint.org/
  • http://eslint.org/docs/rules/

License

MIT