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

eslint-config-topcoder

v2.0.0

Published

ESLint config for nodejs, react and babel

Downloads

41

Readme

eslint-config-topcoder

Build Status

This package contains ESLint configs for applications:

  • nodejs v7 (backend application)
  • nodejs v7 with babel (backend application written in babel)
  • react

It contains plugins:

Installation

Nodejs

npm install --save-dev eslint-config-topcoder

Configure .eslintrc

{
  "extends": "eslint-config-topcoder/nodejs"
}

Nodejs + babel

npm install --save-dev eslint-config-topcoder eslint-plugin-babel@^4.0.0 babel-eslint@^7.1.1

Configure .eslintrc

{
  "extends": "eslint-config-topcoder/nodejs-babel"
}

React

npm install --save-dev eslint-config-topcoder eslint-plugin-babel@^4.0.0 eslint-plugin-react@^6.8.0 babel-eslint@^7.1.1

Configure .eslintrc

{
  "extends": "eslint-config-topcoder/react"
}

Add scripts to package.json

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

Run scripts with -s flag

  npm run lint -s
  npm run lint:fix -s

General notes

  1. It's not allowed to disable rules. The purpose of this config is to keep consistent styles in all topcoder projects.
    However some exception are allowed.

  2. You can disable rules in configuration/setup files.
    Example:

    app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
       res.json({
         error: err.message
       });
    });

    ExpressJS requires to create a function with 4 parameters for error handling, but it may happen that we don't use some parameters.
    Following example is not allowed, because socket can be removed.

    io.on('connection', (socket) => { // eslint-disable-line no-unused-vars
      winston.info('socket connection established');
    });
  3. magic-numbers Following magic numbers are allowed: -1, 0, 1.
    In some cases you can disable this rule:

  • Math computations

    
    const avg = (foo + bar) / 2; // eslint-disable-line magic-numbers
  • Unit tests
    Unit tests usually contain hard-coded data, and magic-numbers can be problematic.

  • In following cases it's not allowed to disable magic-numbers
    bad

    res.status(400);
    res.json({error: 'some validation error'});

    good

    import HttpStatus from 'http-status';
       
    res.status(HttpStatus.BAD_REQUEST);
    res.json({error: 'some validation error'});

    bad

    if (foo.status === 1) {
       
    }

    good

    const ACTIVE_STATUS = 1;
       
    if (foo.status === ACTIVE_STATUS) {
       
    }
  1. You should disable only using inline commands:
    bad (all rules are disabled)
    
    // eslint-disable-line
    good (only 1 rule is disabled)
    
    // eslint-disable-line magic-numbers
  2. Exceptions for import/no-unresolved
    It's allowed to add exceptions if you use aliases (mostly React).
    For example:
    
    'import/no-unresolved': [2, { ignore: ['^components/', '^containers/', '^services/', '^layouts/'] }]

Config for unit tests

If test directory contains unit tests, you should create test/.eslintrc and extend the base config.
Example:

{
  "extends" : "../.eslintrc",
  "env"     : {
    "mocha" : true
  },
  "globals": {
    "expect": true,
  },
  "rules": {
    // allow chai asserts like `expect(foo).to.be.true`
    "no-unused-expressions": 0,
    "no-magic-numbers": 0,
    "max-lines": 0,
  }
}

Contributors

License

MIT