Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-decorator-position

NullVoxPopuli106.1kMIT6.0.0

ESLint plugin for enforcing decorator position

eslint, ember, ember.js, plugin, styleguide, rules, decorators

readme

eslint-plugin-decorator-position

NPM version NPM downloads

An ESlint plugin that provides set of rules enforcing consistent decorator positions

❗️Requirements

🚀 Usage

1. Install plugin

pnpm add -D eslint-plugin-decorator-position

Or

yarn add --dev eslint-plugin-decorator-position

Or

npm install --save-dev eslint-plugin-decorator-position

2. Modify your eslint config

For modern 'flat config', append the eslint-plugin-decorator-position config to your eslint.config.js file:

module.exports = [
+ ...require('eslint-plugin-decorator-position/config/recommended'),
  {
    languageOptions: {
      parser: require('@babel/eslint-parser'),
      parserOptions: {
        requireConfigFile: false,
        babelOptions: {
          plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
        },
      },
    },
  },
];

Or for the legacy eslint config format, extend the base config provided by eslint-plugin-decorator-position:

// .eslintrc.js
module.exports = {
  parser: '@babel/eslint-parser',
  // parser: '@typescript-eslint/parser',
  plugins: ['decorator-position'],
  extends: [
    'plugin:decorator-position/ember' // or other configuration
  ],
  rules: {
    // override rule settings from extends config here
    // 'decorator-position/decorator-position': ['error', { /* your config */ }]
  }
};

3. Using with Prettier

Since eslint 8, the printWidth option must be specified to be compatible with the eslint-plugin-prettier rule prettier/prettier

// eslint.config.js
module.exports = [
  ...require('eslint-plugin-decorator-position/config/recommended'),
  {
    languageOptions: {
      parser: require('@babel/eslint-parser'),
      parserOptions: {
        requireConfigFile: false,
        babelOptions: {
          plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
        },
      },
    },
  },
+ rules: {
+   'decorator-position/decorator-position': ['error', { printWidth: 100 }],
+   'prettier/prettier': ['error', { printWidth: 100 }]
+ }
]

or

// .eslintrc.js
module.exports = {
  parser: '@babel/eslint-parser',
  plugins: ['decorator-position'],
  extends: [
    'plugin:decorator-position/ember' // or other configuration
  ],
  rules: {
    'decorator-position/decorator-position': ['error', { printWidth: 100 }],
    'prettier/prettier': ['error', { printWidth: 100 }]
  }
};

If there is a .prettierrc.js file, that will be read instead, and printwidth is not needed.

🧰 Configurations

'Flat' configurations: | | Name | Description | |:---|:-----|:------------| | | /config/base | Only installs the plugin. You can use it to configure rules as you wish. | | | /config/rules | Only configures the rules. Expects the plugin to be installed. | | | /config/recommended | Installs the plugin and configures the rules |

Legacy configurations: | | Name | Description | |:---|:-----|:------------| | | base | contains no rules settings, but the basic eslint configuration suitable for any project. You can use it to configure rules as you wish. | | :hamster: | ember | extends the base configuration by enabling the recommended rules for ember projects. |

Manual plugin installation

If you prefer to manage the config yourself, the plugin can be installed like this:

// eslint.config.js
module.exports = [
  // ... your existing config
  plugins: {
+   "decorator-position": require("eslint-plugin-decorator-position"),
  },
  rules: {
+   'decorator-position/decorator-position': 'error',
  }
]

🍟 Rules

Rules are grouped by category to help you understand their purpose. Each rule has emojis denoting:

  • What configuration it belongs to
  • :wrench: if some problems reported by the rule are automatically fixable by the --fix command line option

Style

| | Rule ID | Description | |:---|:--------|:------------| | :white_check_mark::wrench: | decorator-position | enforce consistent decorator position on properties and methods |

For the simplified list of rules, go here.

🍻 Contribution Guide

If you have any suggestions, ideas, or problems, feel free to create an issue, but first please make sure your question does not repeat previous ones.

Creating a New Rule

  • Create an issue with a description of the proposed rule
  • Create files for the new rule:
    • lib/rules/new-rule.js (implementation, see no-proxies for an example)
    • docs/rules/new-rule.md (documentation, start from the template -- raw, rendered)
    • tests/lib/rules/new-rule.js (tests, see no-proxies for an example)
  • Run yarn update to automatically update the README and other files (and re-run this if you change the rule name or description)
  • Make sure your changes will pass CI by running:
    • yarn test
    • yarn lint (yarn lint:js --fix can fix many errors)
  • Create a PR and link the created issue in the description

Note that new rules should not immediately be added to the recommended configuration, as we only consider such breaking changes during major version updates.

Running smoke tests and creating reproductions

To run smoke tests:

./scripts/smoke-test.sh

it will prompt you with which test to run.

To create a reproduction,

  1. first make sure there is an open issue describing the problem your encountering.
  2. then create a folder in smoke-tests/issue-reproductions/ named ofter the issue number. example: smoke-tests/issue-reproductions/196/
  3. The minimum required files are:
    • package.json - for declaring which dependencies are being tested (or * if it doesn't matter for your particular test)
    • a js or ts file to demonstrate the "correct" state. After a smoke-test runs, a git diff is checked to ensure 0 changes.
    • .eslintrc.js - to define what configuration / rules / plugins / etc may be relevant.

SemVer Policy

How does this project interpret patch / minor / breaking changes?

  • patch: a change that fixes currently broken behavior. Does not cause formatting to change when people update unless a previous patch/feature accidentally broke formatting in a breaking way.
  • minor: a change that does not impact formatting
  • breaking: a major change that is not backwards compatible and would intentionally cause formatting changes to occur

🔓 License

See the LICENSE file for license rights and limitations (MIT).

changelog

eslint-plugin-decorator-position

6.0.0

Major Changes

5.0.1 (2022-07-19)

5.0.2

Patch Changes

  • #587 9629734 Thanks @NullVoxPopuli! - Internal: switch to changeset for automated release. This gives more control over the release process, and alleviates contributors from needing to know of any conventions about commits or anything like that.

Bug Fixes

5.0.0 (2022-07-15)

Features

  • support eslint@8 (4193fac)
  • upgrade: adding eslint v7 ci testing (fef593c)
  • upgrade: adding exports of private eslint api on first rule run (c8186e3)
  • upgrade: adding exports of private eslint api on first rule run (582543e)
  • upgrade: adding postinstall script to exports private eslint api (7ad2761)
  • upgrade: adding support for eslint v6 (d549fe1)
  • upgrade: adding support for eslint v7 (afdc876)
  • upgrade: drop automatic detection of printWidth (deb4c07)
  • upgrade: eslint@8 (e00f402)
  • upgrade: fix ci (6f382ca)
  • upgrade: fix lint (882599d)
  • upgrade: fix lint (49603f9)
  • upgrade: fix smoke tests (359dec5)
  • upgrade: fix smoke tests (1648e88)
  • upgrade: rolling back formatting and package version (01b0087)
  • upgrade: upgrade readme (9452f5e)

BREAKING CHANGES

    • node 12 is no longer supported, support for node 18 was added.
  • eslint8 will not support the prettier/prettier rule. reading the config from prettier/prettier is not supported by eslint. It's possible it could maybe be added later through hacks (currently in place) / private api usage, but eslint8 does not give access to the config for a file.

4.0.1 (2021-09-29)

Bug Fixes

  • #421: fix issue #421 - crash when getting name of MemberExpression (777d047)

4.0.0 (2021-09-28)

chore

BREAKING CHANGES

  • ci: drop support for eslint@5

this technically isn't a breaking change, as eslint@5 likely never worked. But now CI is testing supported versions of eslint.

3.0.1 (2021-09-28)

Bug Fixes

  • readme: update readme to reflect new node support policy (84ab1f1)

3.0.0 (2021-09-28)

chore

  • drop support fore node 10 (5130cc1)

BREAKING CHANGES

  • node < 12 is no longer supported.

Added node 14 and 16 to the test matrix

2.2.29 (2021-07-20)

Bug Fixes

  • 313: only count chars on first line of multi-line decorator value (1a1bc21)

2.2.28 (2021-06-03)

Bug Fixes

  • #337: wrap require prettier in a try-catch so that we don't throw when dep tree has no prettier (f7594ff), closes #337

2.2.27 (2021-05-27)

Bug Fixes

  • deps: move linter deps to peer deps (a97d8ff)

2.2.26 (2021-05-22)

Bug Fixes

  • deps: update dependency eslint to ^7.27.0 (8097d2d)

2.2.25 (2021-05-08)

Bug Fixes

  • deps: update dependency eslint to ^7.26.0 (7dd7fb1)

2.2.24 (2021-04-24)

Bug Fixes

  • deps: update dependency eslint to ^7.25.0 (f7c2e62)

2.2.23 (2021-04-10)

Bug Fixes

  • deps: update dependency eslint to ^7.24.0 (a7baeea)

2.2.22 (2021-03-27)

Bug Fixes

  • deps: update dependency eslint to ^7.23.0 (d745a5a)

2.2.21 (2021-03-23)

Bug Fixes

  • deps: update dependency eslint to ^7.22.0 (9b75f98)

2.2.20 (2021-03-22)

Bug Fixes

  • include indentation when counting line width (b86643a)

2.2.19 (2021-02-13)

Bug Fixes

  • deps: update dependency eslint to ^7.20.0 (b16acc1)

2.2.18 (2021-01-31)

Bug Fixes

  • deps: update dependency eslint to ^7.19.0 (b744841)

2.2.17 (2021-01-16)

Bug Fixes

  • deps: update dependency eslint to ^7.18.0 (24cf543)

2.2.16 (2021-01-02)

Bug Fixes

  • deps: update dependency eslint to ^7.17.0 (76e5695)

2.2.15 (2020-12-19)

Bug Fixes

  • deps: update dependency eslint to ^7.16.0 (34b4172)

2.2.14 (2020-12-05)

Bug Fixes

  • deps: update dependency eslint to ^7.15.0 (c174771)

2.2.13 (2020-11-23)

Bug Fixes

  • #214: update private prettier path (a141e7a), closes #214
  • internal: ci was missing two smoke tests (27080ce)

2.2.12 (2020-11-21)

Bug Fixes

  • deps: update dependency eslint to ^7.14.0 (810e542)

2.2.11 (2020-11-09)

Bug Fixes

  • typo: warning flag should be false by default (e019bf2)

2.2.10 (2020-11-09)

Bug Fixes

  • #198: fix issue #198 by only displaying warn once (98a18a1)

2.2.9 (2020-11-09)

Bug Fixes

  • #196: fix prettier unspecified printWidth (2c327c8), closes #195

2.2.8 (2020-11-09)

Bug Fixes

  • #195: decorators using declare now respect prettier (607f4ba), closes #195

2.2.7 (2020-11-08)

Bug Fixes

  • deps: update dependency eslint to ^7.13.0 (4e3f25a)

2.2.6 (2020-10-30)

Bug Fixes

  • readme: ESLint configuration key name matches rule name (#189) (7935c85)

2.2.5 (2020-10-27)

Bug Fixes

  • deps: update dependency eslint to ^7.12.1 (352b54d)

2.2.4 (2020-10-24)

Bug Fixes

  • deps: update dependency eslint to ^7.12.0 (110c64c)

2.2.3 (2020-10-09)

Bug Fixes

  • deps: update dependency eslint to ^7.11.0 (dfbba5c)

2.2.2 (2020-10-03)

Bug Fixes

  • widen eslint version in package.json (46fc297)

2.2.1 (2020-06-29)

Bug Fixes

  • deps: update dependency eslint to v7.3.1 (3dd555c)

2.2.0 (2020-06-29)

Features

  • support printWidth and optionally inherit from prettier config (e3e621d)
  • take alternate path when line length is greater than printWidth (09c4440)

2.1.0 (2020-05-23)

Bug Fixes

Features

  • internal: support changelog generation (e89171c)

1.0.3 (2020-05-23)

Bug Fixes

  • internal: resolve bad lint rule (706076e)
  • tests: ember smoke test by upgrading eslint (e82992c)
  • tests: prettier smoke test had invalid eslint config (67eccfd)
  • tests: re-fix tests due to imlint (82ae9c1)

Features

  • internal: support changelog generation (e89171c)

2.0.3 (2020-04-21)

Bug Fixes

  • config: normalizeConfig broke (8988541)
  • deps: add babel-eslint to smoke tests (ce8eafe)
  • docs: custom rule (#33) (724551d)
  • readme: shorten readme example (b8e5b2d)
  • readme: shorten readme example (540a1c5)
  • readme: update example eslintrc (b3bb8c0)
  • rule: ignore same-line multi-line decorators (7c34aac)
  • test: fail the smoke test if anything fails (59073cd)
  • tests: smoke-test script needs to install main deps first (25589a0)

chore

  • change the defaults to be more ergonomic (fdfc0af)

Features

  • add default positioning for decorators (f3fbb44)

BREAKING CHANGES

  • the 1.x.x configuration is no longer compatible. However, the 2.x.x configuration has better defaults, and should require less overall configuration between projects.

1.0.4 (2020-03-24)

Bug Fixes

  • package.json version does not match tag (439b5f3)

1.0.3 (2020-03-24)

Bug Fixes

  • readme: update link to ember config in readme (2efc4f7)

1.0.2 (2020-03-24)

Bug Fixes

  • multi-line decorators now behave appropriately (c5bf6be)
  • update minimum node version in readme (62b4014)

1.0.0 (2020-03-23)

Bug Fixes

  • use correct semantic-release-cli command (6ebae4f)
  • use correct semantic-release-cli command (ac5afdf)
  • use correct semantic-release-cli command (afa8188)