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

@atomspace/eslint

v6.3.0

Published

Neutrino preset for adding ESLint config, following the Atom Space code style

Downloads

131

Readme

Atom Space ESLint Preset

@atomspace/eslint is a Neutrino preset that supports linting JavaScript projects with ESLint config used in Atom Space.

NPM version NPM downloads Build Status

Features

  • Zero upfront configuration necessary to start linting your project
  • React support
  • Vue support
  • Node.js support
  • Accessibility linting in React and Vue
  • JSON support
  • Yarn Berry support
  • Highly visible during development, fails compilation when building for production
  • Promises linting
  • Module systems linting (ES, CommonJS, AMD) considering Webpack modules paths resolving
  • Regex shorthand to improve readability
  • ESLint comments linting
  • JSDoc syntax linting
  • ESLint plugins linting
  • Jest tests linting
  • Security rules
  • File names linting
  • Various libraries linting
  • Markdown code fragments linting
  • Checking for best practices
  • Easily extensible to customize your project as needed

Requirements

  • Node.js v10+
  • Neutrino v9
  • Webpack 4
  • ESLint 7.4+

Installation

@atomspace/eslint can be installed using NPM. Inside your project, make sure neutrino, eslint and @atomspace/eslint are development dependencies. You will also be using another Neutrino preset for building your application source code.

npm install --save-dev neutrino eslint "@atomspace/eslint"

Quickstart

After adding the Atom Space preset to your Neutrino-built project, edit your project's package.json and .neutrinorc.js to add the preset for linting before your build presets. Make it the first in the list of presets

.neutrinorc.js

let eslint = require('@atomspace/eslint');

module.exports = {
   use: [
      eslint()

      // put your rest of presets here
   ]
};

package.json

{
   "scripts": {
      "build": "webpack --mode production",
      "start": "webpack --mode development",
      "lint": "eslint ./ --fix"
   }
}

@atomspace/eslint, provides an .eslintrc() output handler for generating the ESLint configuration in a format suitable for use in an .eslintrc.js file. This allows the ESLint CLI to be used outside of building the project, and for IDEs and text editors to provide linting hints/fixes.

Create a .eslintrc.js file in the root of the project, containing:

.eslintrc.js

let neutrino = require('neutrino');

module.exports = neutrino().eslintrc();

Building

If you have a Neutrino build preset in .neutrinorc.js, start the app in development mode via webpack --mode development. Then check your console for any linting errors. If everything is successful, you should see no errors in the console. ESLint errors visible during development are reported, but will still continue to build and serve your project.

❯ npm start

✔ Development server running on: http://localhost:5000
✔ Build completed

ERROR in ./src/index.js

/src/index.js
  7:1   warning  Unexpected console statement                no-console
  7:14  error    A space is required after '{'               babel/object-curly-spacing
  7:20  error    Missing space before value for key 'hello'  key-spacing
  7:27  error    A space is required before '}'              babel/object-curly-spacing

✖ 4 problems (3 errors, 1 warning)

ESLint errors during production mode build will not build the project, and will cause the command to fail your build when creating a bundle via webpack --mode production.

❯ npm run build

/src/index.js
  6:1   warning  Unexpected console statement            no-console
  6:14  error    A space is required after '{'           babel/object-curly-spacing
  6:16  error    Missing space before value for key 'a'  key-spacing
  6:17  error    A space is required before '}'          babel/object-curly-spacing

✖ 4 problems (3 errors, 1 warning)

error Command failed with exit code 1.

Preset options

Configuration

If you wish to customize what is included, excluded, or any ESLint options, you can provide an options object with the preset and this will be merged with defaults. Define eslint property to override ESLint configuration.

Example: Include a plugin, browser and Node environments and turn off semicolons from being required as defined by the Atom Space rules.

let eslint = require('@atomspace/eslint');

module.exports = {
   use: [
      eslint({
         eslint: {
            plugins: ['fp'],
            env: {
               browser: true,
               node: true
            },
            rules: {
               semi: 'off'
            }
         }
      })
   ]
};

EcmaScript

This preset enables rules compatible with the latest EcmaScript version by default. This is suitable for the latest browsers or if you use transpilation during a build step. However in some cases old good ES5 may be required. You may disable modern features by overriding esnext property:

module.exports = {
   use: [
      eslint({ esnext: false })
   ]
};

This will disable:

  • ES modules
  • new ES global namespaces
  • new syntax like destructuring, arrow functions, default function arguments, classes, etc.
  • implied strict mode (you will have to define use strict directive in every file)

Compatibility

Browser

In case you want to check a compatibility with certain browsers you may pass browsers option to settings. But it is recommended to use it only in case if there is no Babel transpilation for such browsers.

Configure supported browsers in .neutrinorc.js (see browserslist):

module.exports = {
   use: [
      eslint({ browsers: ['ie >= 8'] })
   ]
};

Node

If you want to check a compatibility with a NodeJS version pass node option to settings. This will check the code for EcmaScript compatibility. It is recommended to use it only if there is no Babel transpilation.

module.exports = {
   use: [
      eslint({ node: '>=8.0.0' })
   ]
};

Also you can enable linting of NodeJS features and deprecated API providing engines in your package.json. This will highlight usage of deprecated properties, methods and global variables.

{
   "engines": {
      "node": ">=8.3.0"
   }
}

ESLint CLI

You can find more details how to run ESLint in the CLI in the official documentation.

Usually ESLint is a part of Webpack build configuration and any violation will prevent build and report errors. So it is not necessary to run ESLint separately during CI/CD for instance. But if you don't use Webpack and would like to include linting in your pipeline you can use this configuration of scripts

package.json

{
   "scripts": {
      "eslint": "eslint ./",
      "pretest": "npm run eslint -- --max-warnings 0 --format codeframe",
      "lint": "npm run eslint -- --fix"
   }
}

Running of tests will lint before and fail if there are violations

❯ npm test

Running lint command will auto-fix and report left violations

❯ npm run lint

VSCode tips

To enable ESLint in Visual Studio Code you should have the ESLint extension installed.

These are suggested workspace settings related to @atomspace/eslint rules:

.vscode/settings.json

{
   "editor.insertSpaces": false,
   "editor.detectIndentation": false,
   "jshint.enable": false,
   "prettier.enable": false,
   "editor.formatOnSave": false,
   "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
   },
   "javascript.format.enable": true,
   "javascript.validate.enable": false,
   "files.eol": "\n",
   "files.insertFinalNewline": false,
   "[markdown]": {
      "editor.tabSize": 3,
      "editor.insertSpaces": true
   },
   "eslint.options": {
      "extensions": [".js", ".jsx", ".html", ".md", ".vue", ".json", ".jsonc", ".json5", ".json6"]
   },
   "eslint.validate": ["javascript", "javascriptreact", "html", "markdown", "vue", "json", "jsonc", "json5", "json6"],
   "vetur.validation.template": false
}

When project has been initially installed you need to restart an editor. After this ESLint will start to highlight and auto-fix errors in your code on file save.

@atomspace/eslint can work in your editor even if there is no build infrastructure (npm start / npm run build). You can install it to any kind of JavaScript projects following the ESLint CLI guide above.