Skip to content

Instantly share code, notes, and snippets.

@rochajg
Last active November 1, 2019 19:30
Show Gist options
  • Save rochajg/ae171dbc16f6fb28081494d66db287da to your computer and use it in GitHub Desktop.
Save rochajg/ae171dbc16f6fb28081494d66db287da to your computer and use it in GitHub Desktop.
How to setup the main lint to StandardJS

How to setup StandardJS lint

The npm packages

First install this packages as dev dependencies

npm i -D eslint eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard

#or

yarn add -D eslint eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard

Next step is add this flag to your .eslintrc.json:

"env": {
    "commonjs": true,
    "es6": true,
    "node": true
  },
  "extends": "standard"

How to use in code

In your code you'll use single quotes (') and omit the semicolon (;) like this:

const moment = require('moment')

module.exports = app => {
  const getTasks = (req, res) => {
    const date = req.query.date
      ? req.query.date
      : moment()
        .endOf('day')
        .toDate()

    app
      .db('tasks')
      .where({ userId: req.user.id })
      .where('estimateAt', '<=', date)
      .orderBy('estimateAt')
      .then(tasks => res.json(tasks))
      .catch(err => res.status(400).json(err))
  }

  return { getTasks }
}

If you're using VS Code and Prettier, add this option on your settings.json: "prettier.eslintIntegration": true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment