Shareable ESLint config for Scratch
Find a file
renovate[bot] bd642d5a3b
Some checks failed
Build eslint-config-scratch / build-eslint (push) Has been cancelled
chore(deps): lock file maintenance
2024-11-13 01:31:16 +00:00
.github chore(deps): pin dependencies 2024-02-16 01:32:09 +00:00
.husky chore: add husky hook for commitlint 2022-10-13 10:01:05 -07:00
.gitattributes use scratch-renovate-config:conservative 2021-07-22 14:45:55 -07:00
.gitignore Initial commit 2016-10-21 16:56:57 -04:00
CHANGELOG.md chore(release): 9.0.9 [skip ci] 2024-09-11 03:06:34 +00:00
commitlint.config.js chore: add and configure commitlint 2022-10-13 10:01:05 -07:00
es6.js feat: added no-prototype-builtins rule, set to error 2020-11-09 16:16:58 -05:00
index.js chore(deps): use @babel/eslint-parser instead of babel-eslint 2022-05-20 12:01:08 -07:00
LICENSE docs(legal): Add LICENSE and TRADEMARK 2016-10-24 16:36:06 -04:00
node.js feat(all): Move all warnings to errors 2017-08-15 10:02:52 -04:00
package-lock.json chore(deps): lock file maintenance 2024-11-13 01:31:16 +00:00
package.json chore(deps): update dependency @babel/eslint-parser to v7.25.9 2024-10-25 18:31:51 +00:00
react.js feat(react/sort-prop-types): Remove React prop sort 2017-11-21 10:25:33 -05:00
README.md docs(readme.md): update installation instructions 2022-05-23 08:55:24 -07:00
release.config.js ci(semantic-release): use scratch-semantic-release-config 2022-10-13 10:01:05 -07:00
renovate.json5 Revert "chore(deps): use js-lib-bundled Renovate config" 2024-02-21 10:35:20 -08:00
TRADEMARK Update TRADEMARK 2018-06-18 13:20:35 -04:00

Scratch ESLint config

Greenkeeper badge

eslint-config-scratch defines the eslint rules used for Scratch Javascript projects

Installation

Install the config along with its peer dependencies, eslint and babel-eslint.

npm install -DE eslint-config-scratch eslint@^8 @babel/eslint-parser@^7

If you're using the React config, also install the dependency for that

npm install -DE eslint-plugin-react@^7

Usage

The configuration is split up into several modules:

  • scratch: The base configuration. Always extend this.
  • scratch/node: Rules for node, e.g., server-side code, tests, and scripts
  • scratch/es6: Rules for ES6, for use when you're transpiling with webpack
  • scratch/react: Rules for React projects

Usually web projects have a mix of node and web environment files. To lint both with the appropriate rules, set up a base .eslintrc.js with the rules for node and then override the node configuration in src (where web code usually lives). E.g., with a file structure like this:

scratch-project
- .eslintrc.js
- package.json
- src
  - .eslintrc.js
  - index.js

Your config files should be set up like

// scratch-project/.eslintrc.js
module.exports = {
    extends: ['scratch', 'scratch/es6', 'scratch/node']
};

// scratch-project/src/.eslintrc.js
module.exports = {
    root: true,
    extends: ['scratch', 'scratch/es6', 'scratch/react'],
    env: {
        browser: true
    }
};

This will set up all the files in the project for linting as Node.js by default, except for those in src/, which will be linted as ES6 and React files.

If you're linting React, also make sure your lint script lints .jsx files:

"scripts": {
    "lint": "eslint . --ext .js,.jsx"
}

Committing

This project uses semantic release to ensure version bumps follow semver so that projects using the config don't break unexpectedly.

In order to automatically determine the type of version bump necessary, semantic release expects commit messages to be formatted following conventional-changelog.

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

subject and body are your familiar commit subject and body. footer is where you would include BREAKING CHANGE and ISSUES FIXED sections if applicable.

type is one of:

  • fix: A bug fix Causes a patch release (0.0.x)
  • feat: A new feature Causes a minor release (0.x.0)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance May or may not cause a minor release. It's not clear.
  • test: Adding missing tests or correcting existing tests
  • ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit

Use the commitizen CLI to make commits formatted in this way:

npm install -g commitizen
npm install

Now you're ready to make commits using git cz.

Breaking changes

If you're committing a change that makes the linter more strict, or will otherwise require changes to existing code, ensure your commit specifies a breaking change. In your commit body, prefix the changes with "BREAKING CHANGE: " This will cause a major version bump so downstream projects must choose to upgrade the config and will not break the build unexpectedly.