Shared linting configuration for braintree js projects.
- index.js: shared configuration
- client.js: client side configuration
- server.js: server side configuration
- jsdoc.js: jsdoc configuration
Install eslint@^9
npm install eslint@^9Install the ESLint config
npm i --save-dev eslint-config-braintreeEslint requires all the plugins that the config uses to be installed at the root of the project as well.
npm i --save-dev @typescript-eslint/eslint-plugin eslint-plugin-prettierClone this repo, then install the project's development dependencies:
npm installRun unit tests via the command:
npm run testIn your project's eslint.config.js:
const braintreeConfig = require("eslint-config-braintree");
module.exports = braintreeConfig;const braintreeClientConfig = require("eslint-config-braintree/client");
module.exports = braintreeClientConfig;const braintreeServerConfig = require("eslint-config-braintree/server");
module.exports = braintreeServerConfig;const braintreeClientConfig = require("eslint-config-braintree/client");
const braintreeEs6Config = require("eslint-config-braintree/es6");
module.exports = [...braintreeClientConfig, ...braintreeEs6Config];In your project's .eslintrc.*:
---
extends: braintree---
extends: braintree/client---
extends: braintree/server---
extends:
- braintree/client
- braintree/es6{
"extends": "braintree"
}{
"extends": "braintree/client"
}{
"extends": "braintree/server"
}{
"extends": ["braintree/client", "braintree/es6"]
}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 }],
},
},
];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 }]
}
}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.