Skip to content

braintree/eslint-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-config-braintree

Shared linting configuration for braintree js projects.

Consuming

Install eslint@^9

npm install eslint@^9

Install the ESLint config

npm i --save-dev eslint-config-braintree

Eslint requires all the plugins that the configu uses to be installed at the root of the project as well.

npm i --save-dev @typescript-eslint/eslint-plugin eslint-plugin-prettier

ESLint Flat Config (v9+)

In your project's eslint.config.js:

Default (Flat Config)

const braintreeConfig = require("eslint-config-braintree");

module.exports = braintreeConfig;

Browserify

const braintreeClientConfig = require("eslint-config-braintree/client");

module.exports = braintreeClientConfig;

Node

const braintreeServerConfig = require("eslint-config-braintree/server");

module.exports = braintreeServerConfig;

Browserify + ES6

const braintreeClientConfig = require("eslint-config-braintree/client");
const braintreeEs6Config = require("eslint-config-braintree/es6");

module.exports = [...braintreeClientConfig, ...braintreeEs6Config];

Legacy Configuration (.eslintrc - ESLint v8 and below)

In your project's .eslintrc.*:

yaml

Default (yaml)
---
extends: braintree
Browserify (yaml)
---
extends: braintree/client
Node (yaml)
---
extends: braintree/server
Browserify + ES6 (yaml)
---
extends:
  - braintree/client
  - braintree/es6

json

Default (json)
{
  "extends": "braintree"
}
Browserify (json)
{
  "extends": "braintree/client"
}
Node (json)
{
  "extends": "braintree/server"
}
Browserify + ES6 (json)
{
  "extends": ["braintree/client", "braintree/es6"]
}

Customizing Rules

Flat Config (ESLint v9+)

You can extend and override rules by adding additional configuration objects to the array:

const braintreeConfig = require("eslint-config-braintree");

module.exports = [
  ...braintreeConfig,
  {
    files: ["**/*.ts", "**/*.tsx"],
    rules: {
      "no-new-object": "warn", // Change from error to warn
    },
  },
];

For different file patterns:

const braintreeConfig = require("eslint-config-braintree");

module.exports = [
  ...braintreeConfig,
  {
    files: ["**/*.js"],
    rules: {
      "no-multi-spaces": ["error", { ignoreEOLComments: false }],
    },
  },
];

Legacy Configuration

You can specify a .eslintrc for a subdirectory to change the rules that are enforced. For instance, in a node project you could extend from eslint-config-braintree/server at the top-level, and eslint-braintree-config/client at the public/.eslintrc level.

See Configuration File Formats for information on all supported .eslintrc file formats.

To override rules, add the new config under rules in your rc file. Be sure to properly override any options set by the parent. See Extending Configuration Files for details.

For example, to change the no-new-object rule to warn instead of error:

---
extends: braintree/server
rules:
  no-new-object: warn
{
  "extends": "braintree/server",
  "rules": {
    "no-new-object": "warn"
  }
}

In another example, to allow end of line comments, you'd override the "no-multi-spaces" rule options:

---
extends: braintree/server
rules:
  no-multi-spaces:
    - error
    - ignoreEOLComments: false
{
  "extends": "braintree/server",
  "rules": {
    "no-multi-spaces": ["error", { "ignoreEOLComments": false }]
  }
}

Test Files

By default, any files in a __tests__ folder, whether at the top level of the directory or within another directory will be configured to be used in the Jest and ES2020 environments.

About

Shared linting configuration for braintree js projects

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 8