0.4.3 • Published 5 years ago

eslint-plugin-tangerine v0.4.3

Weekly downloads
934
License
MIT
Repository
github
Last release
5 years ago

eslint-plugin-tangerine

A set of Eslint rules developed by Atlassian as part of Tangerine 🍊.

Tangerine

Installation

Install ESLint locally or globally:

$ yarn add --dev eslint

If you've installed ESLint globally, you'll have to install the Tangerine plugin globally too. Otherwise, install it locally:

$ yarn add --dev eslint-plugin-tangerine

Configuration

Specify tangerine as a plugin in .eslintrc.js file:

{
  "plugins": ["tangerine"]
}

We export a number of shareable configs that provide a set of pre-configured rules to help enforce our guidelines.

Each of them are concerned with a specific theme and/or guideline.

The list of configs are:

  • packages - Contains all package-related rules, configured to adhere to the package structure guidelines
  • recommended - The recommended config, includes all other configs

To use a shareable config, simply add it to the extends field.

E.g.

{
  "extends": ["plugin:tangerine/recommended"]
}

See the ESLint docs on extending shareable configs for more information.

Alternatively, to configure or override certain rules yourself, you can now enable them as follows:

{
  "rules": {
    "tangerine/import/restricted-paths": "error"
  }
}

Shared settings

Certain rules are able to be customised using ESLint's shared settings feature.

The settings are keyed under tangerine and are as follows:

{
  "settings": {
    "tangerine": {
      "message": "Custom error message suffix."
    }
  }
}

message

This will append an extra custom error message to each rule that supports a message option, which will be most rules in the shareable configs.

Rules

Rules with the wrench icon 🔧 can automatically be fixed by passing the --fix option to the command line

i18n

import

other

react

Contributing

All rules are located in separate directories, in the corresponding rules/<ruleCategory> directory. The rule's name must be identical to its directory name.

Every rule must contain:

After adding a new rule, run yarn docs:generate-pkg from the root directory to add a link to the frontpage README.md file.

All rules are exposed automatically.

To change this file, edit template instead, then run yarn docs:generate-pkg from the root directory

Testing

To help test your rules, we've created an extension to expect called toMatchEslintResults(). It's intended to streamline the running of a particular code block against all of the rules in this plugin, and match a subset of the results against what you'd expect them to be.

expect(code).toMatchEslintResults(results);

For example:

test('import/no-default-export', () => {
  expect("export default 'bar';\n").toMatchEslintResults({
    messages: [{ message: 'Prefer named exports.' }],
  });
});

The results object can be a subset of the results returned by ESLint. However, if you're asserting messages, then message in the array that you're trying to match must match the index in which it appears in the actual results.

Bump plugin version

After you've merged the changes, you need to

  • update the package version in package.json
  • update the Changelog.md
  • create a new PR with the bump. Wait for it to be merged. Example of such PR.
  • Manual publish the new version of the package: npm publish.