nullvoxpopuli / eslint-plugin-decorator-position Goto Github PK
View Code? Open in Web Editor NEWESLint plugin for enforcing decorator position
License: MIT License
ESLint plugin for enforcing decorator position
License: MIT License
I stumbled upon this while working on a Stencil component.
Rule configuration: "decorator-position/decorator-position": "error"
(default)
Code:
export class MyComponent {
@State() classes = ["toggle", this.checkedClass(), this.disabledClass()]
.filter(Boolean)
.join(" ");
}
Expected: no warnings (because by default property decorators should be inline)
Actual: Expected @State to be on the line above
I'm using the new es2021
environment in my .eslintrc.json
introduced in ESLint 7.8.0:
{
"env": { "es2021": true },
"plugins": ["decorator-position"],
"rules": {
"decorator-position/decorator-position": "error"
}
}
And eslint-plugin-decorator-position throws the following error:
Error: Error while loading rule 'decorator-position/decorator-position': .eslintrc.json » ./index.json » eslint-config-hardcore » ./base.json:
Environment key "es2021" is unknown
Occurred while linting .eslintrc.json
at node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\shared\config-validator.js:163:19
at Array.forEach (<anonymous>)
at validateEnvironment (node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\shared\config-validator.js:157:30)
at validateConfigArray (node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\shared\config-validator.js:309:9)
at CascadingConfigArrayFactory._finalizeConfigArray (node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:464:13)
at CascadingConfigArrayFactory.getConfigArrayForFile (node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\cli-engine\cascading-config-array-factory.js:275:21)
at CLIEngine.getConfigForFile (node_modules\eslint-plugin-decorator-position\node_modules\eslint\lib\cli-engine\cli-engine.js:933:14)
at lineLength (node_modules\eslint-plugin-decorator-position\lib\rules\decorator-position.js:327:35)
at Object.decoratorPositionRule [as create] (node_modules\eslint-plugin-decorator-position\lib\rules\decorator-position.js:138:27)
at createRuleListeners (node_modules\eslint\lib\linter\linter.js:761:21)
eslint-plugin-decorator-position: 2.2.1
ESLint: 7.8.0
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@babel/core
, @babel/eslint-parser
, @babel/plugin-proposal-decorators
, @changesets/changelog-github
, @changesets/cli
, @eslint/eslintrc
, @vitest/coverage-c8
, @vitest/ui
, babel-eslint
, c8
, eslint
, eslint-config-prettier
, eslint-plugin-eslint-plugin
, eslint-plugin-import
, eslint-plugin-markdown
, eslint-plugin-node
, markdownlint-cli
, npm-run-all
, typescript
, vitest
)@eslint/eslintrc
, @typescript-eslint/parser
, @vitest/ui
, c8
, eslint
, eslint-config-prettier
, eslint-plugin-decorator-position
, eslint-plugin-ember
, eslint-plugin-eslint-plugin
, eslint-plugin-markdown
, eslint-plugin-node
, eslint-plugin-prettier
, prettier
, vitest
).github/actions/pnpm/action.yml
actions/cache v3
pnpm/action-setup v2.2.4
.github/workflows/ci.yml
actions/checkout v3
volta-cli/action v4
actions/checkout v3
volta-cli/action v4
actions/checkout v3
volta-cli/action v4
actions/checkout v3
volta-cli/action v4
volta-cli/action v4
actions/checkout v3
volta-cli/action v4
actions/checkout v3
volta-cli/action v4
actions/checkout v3
changesets/action v1
package.json
@babel/core 7.22.8
@babel/eslint-parser 7.22.7
@babel/plugin-proposal-decorators 7.22.7
@changesets/changelog-github ^0.4.7
@changesets/cli ^2.25.2
@eslint/eslintrc 2.1.0
@typescript-eslint/parser 5.62.0
@vitest/coverage-c8 ^0.31.0
@vitest/ui 0.31.1
c8 8.0.0
common-tags 1.8.2
eslint ^8.44.0
eslint-config-prettier 8.8.0
eslint-plugin-eslint-comments 3.2.0
eslint-plugin-eslint-plugin 5.1.0
eslint-plugin-filenames 1.3.2
eslint-plugin-import 2.27.5
eslint-plugin-markdown 3.0.0
eslint-plugin-node 11.1.0
eslint-plugin-prettier 4.2.1
lerna-changelog 2.2.0
markdownlint-cli 0.35.0
npm-run-all 4.1.5
prettier 2.8.8
typescript 5.1.6
vitest 0.31.1
node 18.16.1
yarn 1.22.19
smoke-tests/integration/external-config-prettier/package.json
smoke-tests/integration/position-default/package.json
yarn 1.22.17
smoke-tests/integration/position-prettier/package.json
smoke-tests/issue-reproductions/147/package.json
babel-eslint ^10.0.3
eslint ^7.9.0
eslint-plugin-decorator-position ^2.2.1
eslint-plugin-ember ^7.1.0
eslint-plugin-node ^10.0.0
loader.js ^4.7.0
smoke-tests/issue-reproductions/195/package.json
smoke-tests/issue-reproductions/196/package.json
smoke-tests/issue-reproductions/289/package.json
smoke-tests/issue-reproductions/313/package.json
No entirely sure on how to create a reproduction example, but mixing indent with decorator-position/decorator-position makes ESLint go crazy.
.eslintrc.js
module.exports = {
extends: ['eslint:recommended'],
root: true,
overrides: [
{
files: ['*.js', '*.ts'],
plugins: ['decorator-position'],
rules: {
'decorator-position/decorator-position': ['error', {
methods: 'above',
properties: 'above'
}],
indent: ['error', 2]
}
}
]
};
example.js
function Decorator() {
console.log();
}
@Decorator() // This line SHOULD have an indent error (has 4 spaces, should have 0), but does NOT
class Class { // This line has the correct indent error (has 4 spaces, should have 0)
@Decorator() // This line SHOULD have an indent error (has 0 spaces, should have 2), but does NOT
prop1; // This line is correct
@Decorator() // This line SHOULD have an indent error (has 4 spaces, should have 2), but does NOT
prop2; // This line SHOULD have an indent error (has 6 spaces, should have 2), but does NOT
} // This line should NOT have an indent error (has 0 spaces, should have 0)
eslint ./example.js --fix
)function Decorator() {
console.log();
}
@Decorator()
class Class {
@Decorator()
prop1;
@Decorator()
prop2;
}
eslint ./example --fix
)function Decorator() {
console.log();
}
@Decorator()
class Class {
@Decorator()
prop1;
@Decorator()
prop2;
}
It seems that decorator-position/decorator-position
is affecting indent
, as ESLint expects the line after the decorator to have one more indent level than the decorator.
Example:
// Would be 113 characters inline
@service('addon-name/-private/do-not-use/the-name-of-the-service')
declare someObfuscatedPrivateService: Service;
if set to be "inline", prettier will want to keep it as is, but the rule would inline the decorator
Prettier (with default options) wraps long decorators to the next line:
export default class Foo {
@bar("baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz")
qux;
}
But then eslint-plugin-decorator-position (with default options) starts saying Expected @bar to be inline
.
I would prefer to not have this warning when using default options.
This error appeared when I upgraded Prettier to 2.2.0:
❯ eslint .
Oops! Something went wrong! :(
ESLint: 7.14.0
TypeError: Error while loading rule 'decorator-position/decorator-position': Cannot read property 'printWidth' of undefined
Occurred while linting C:\eslint-config-hardcore\sort-class-members-test.js
at lineLength (C:\eslint-config-hardcore\node_modules\eslint-plugin-decorator-position\lib\rules\decorator-position.js:337:59)
at Object.decoratorPositionRule [as create] (C:\eslint-config-hardcore\node_modules\eslint-plugin-decorator-position\lib\rules\decorator-position.js:142:26)
It is possible to use certain decorators with () or not:
@service someService;
or
@service() someService;
Would be nice to have a way to define these to be consistent
It shows a error:
/**ProductID which might have an auction */
@Prop() productId: string | number
/**Shows auction state */
@State() auctionState: AuctionState = AuctionState.NONE
Because I don't use semicolons in my code.
Expected: it shouldn't be a error.
I wish this plugin could force also a newline before the decorator.
Currently my config is like this:
"decorator-position/decorator-position": [
"error",
{
"printWidth": 120,
"properties": "above",
"methods": "above"
}
],
Which can fix the following code:
@Input() public param1: Subject<number> = new Subject<Number>;
@Input() public param2: Subject<boolean> = new Subject<boolean>;
@Input() public param3: Subject<string> = new Subject<string>;
to
@Input()
public param1: Subject<number> = new Subject<Number>;
@Input()
public param2: Subject<boolean> = new Subject<boolean>;
@Input()
public param3: Subject<string> = new Subject<string>;
But the preferable output for readability would be
@Input()
public param1: Subject<number> = new Subject<Number>;
@Input()
public param2: Subject<boolean> = new Subject<boolean>;
@Input()
public param3: Subject<string> = new Subject<string>;
Unfortunately I found no other option so far.
We would like to stack multiple lines of decorators, e.g:
//example may not be legit
@memo
@task
thingy = ...
However, it seems that this isn't possible with the lint against with the linters current capabilities?
This is what's happening for me. The one
method fails linting as expected, but as soon as I define a body like in method two
, linting passes when I expect it to fail. This is all of the code:
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class Foo extends Component {
@action one() {}
@action two() {
return 2;
}
}
With ESLint 8.3.0 I get the following fatal error:
Failed to load plugin 'decorator-position' declared in '.eslintrc.json': CLIEngine is not a constructor
at Object.<anonymous> (/example/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:5:13)
It would be nice if we could set defaults for properties, functions, classes and accessors, example:
'decorator-position': [
'error',
{
propertyStartegy: 'sameLine',
functionStrategy: 'newLine',
classStartegy: 'newLine',
accessorStartegy: 'sameLine'
}
]
What do you think about renaming it to onNewLines
?
ESLint v9 was officially released on the 5th of April. This notably also includes making the new flat config format the default. A migration guide can be found here.
Now eslint-plugin-decorator-position with default settings suddenly wants property decorators to be on the line above: https://github.com/EvgenyOrekhov/eslint-config-hardcore/blob/cf5c68bf2e2a0e9e5d853266461cde3d3d160b71/sort-class-members-test.js#L33
when the decorator-position
config has:
defaults: {
properties: 'inline',
}
multi-line decorators conflict with prettier.
example:
@foo({
}) propertyName;
// ^ prettier wants propertyName on the next line
Solution: potentially detect when prettier is present, and and do nothing for this situation? (allowing prettier to move the propertyName
.
Docs at https://github.com/NullVoxPopuli/eslint-plugin-decorator-position#2-modify-your-eslintrcjs put the name of the rules
configuration entry as decorator-position
, but
decorator-position/decorator-position
.
One of those is incorrect, currently, if you try to follow the docs and configure the rules at decorator-position
, eslint is going to show an error ESLint: Definition for rule ;decorator-position' was not found.
Error:
$ yarn lint:js
yarn run v1.22.4
$ eslint . --ext .ts --ext .js
TypeError: Cannot read property '0' of undefined
Occurred while linting /Users/alex/Repos/polarity/neontetra/app/components/channel-selector.js:155
at normalizeConfig (/Users/alex/Repos/polarity/neontetra/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:269:18)
at placeDecoratorsBesideProperty (/Users/alex/Repos/polarity/neontetra/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:182:20)
at /Users/alex/Repos/polarity/neontetra/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:167:9
at Array.forEach (<anonymous>)
at positionDecorator (/Users/alex/Repos/polarity/neontetra/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:154:24)
at ClassProperty[decorators.length=1]:exit (/Users/alex/Repos/polarity/neontetra/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:127:7)
at /Users/alex/Repos/polarity/neontetra/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/alex/Repos/polarity/neontetra/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/alex/Repos/polarity/neontetra/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error Line
@(task(function* () {
// some task
}).drop())
someTask;
Version Info, no custom configuration...using out-of-the-box defaults
eslint-plugin-decorator-position@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-decorator-position/-/eslint-plugin-decorator-position-2.0.1.tgz#7340cf5bd68edaef257cea5b61c4951be0e6c3bc"
integrity sha512-Uv3XnRmFO0YIoH7mzijeUGo0P5To5+bFOq7qrN2wOkIsNS//UR+JrqXv5cm3GVJCj50VfqkbgMutQmZGXK94yA==
dependencies:
"@ember-data/rfc395-data" "^0.0.4"
ember-rfc176-data "^0.3.12"
snake-case "^3.0.3"
FAIL bin/constants/index.js
● Test suite failed to run
TypeError: CLIEngine is not a constructor
at getCachedValues (node_modules/jest-runner-eslint/build/runner/runESLint.js:44:17)
after upgrading eslint 8** im getting above issue could you please help me on it
Is there a way to configure a max length? For example, if you had something like:
@alias('foo.bar.baz.someReallyLongPropertyNameThatIsTooLongToBeInlineOrItBreaksPrettier')
myProp;
I would like to make alias
inline always, unless it is too long and would conflict with prettier formatting, basically.
Is there currently a way to do that?
Don't want them. At all. 😁
Description
Linting fails when using this plugin with Prettier 3.x.
Reproduction
I've created a small example application where Prettier 2.8.8 is used in the main
branch and Prettier 3.0.3 is used
in the non-working-prettier-3.x
branch.
Run pnpm lint:js
in each and the main branch will be successful, while the 3.x branch will throw the error below:
❯ pnpm lint:js
> [email protected] lint:js /home/ross/decorator-position-example
> eslint . --cache
Uncaught error occurred while trying to load prettier config. Please open an issue at https://github.com/NullVoxPopuli/eslint-plugin-decorator-position with the following stack trace:
TypeError: prettier.resolveConfig.sync is not a function
at lineLength (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:411:34)
at Object.decoratorPositionRule [as create] (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:168:26)
at createRuleListeners (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:765:21)
at /home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:937:31
at Array.forEach (<anonymous>)
at runRules (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:882:34)
at Linter._verifyWithoutProcessors (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1181:31)
at Linter._verifyWithConfigArray (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1280:21)
at Linter.verify (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1235:25)
at Linter.verifyAndFix (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1428:29)
Oops! Something went wrong! :(
ESLint: 7.32.0
TypeError: Error while loading rule 'decorator-position/decorator-position': Cannot read properties of undefined (reading 'coreOptions')
Occurred while linting /home/ross/decorator-position-example/.eslintrc.js
at lineLength (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:435:51)
at Object.decoratorPositionRule [as create] (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:168:26)
at createRuleListeners (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:765:21)
at /home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:937:31
at Array.forEach (<anonymous>)
at runRules (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:882:34)
at Linter._verifyWithoutProcessors (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1181:31)
at Linter._verifyWithConfigArray (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1280:21)
at Linter.verify (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1235:25)
at Linter.verifyAndFix (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1428:29)
Oops! Something went wrong! :(
ESLint: 7.32.0
TypeError: Invalid host defined options
at Object.<anonymous> (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/prettier/index.cjs:600:23)
at Module._compile (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
at lineLength (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:376:18)
at Object.decoratorPositionRule [as create] (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected][email protected]/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:168:26)
at createRuleListeners (/home/ross/decorator-position-example/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:765:21)
Cause
It seems that this line in decorator-position.js
along with this line are the culprits.
Prettier 3 moves the synchronous API to the @prettier/sync
module instead of being included in the
default module. Details from Prettier documentation can be found here.
Potential Solution
I am able to modify this segment of the lineLength
function in decorator-position.js
to the following and it is able to lint successfully, but I'm not sure if it is the best solution.
function lineLength(userOptions, filePath) {
if (!prettier) {
try {
// we acknowledge that this might not exist
// eslint-disable-next-line node/no-unpublished-require
prettier = require('prettier');
if (!prettier.resolveConf.sync) {
prettier = require('@prettier/sync');
}
} catch (error) {
// throw an all errors that aren't "Cannot find module"
if (!error.message.includes('Cannot find module')) {
throw error;
}
}
}
...
Commit a97d8ff seems to have removed the runtime dependency on Prettier. Without this dependency, a consuming project that does not reference Prettier will receive a runtime error during linting:
An unhandled exception occurred: Error while loading rule 'decorator-position/decorator-position': Cannot find module 'prettier'
Require stack:
- C:\Code\AgentDash\Frontend\node_modules\eslint-plugin-decorator-position\lib\rules\decorator-position.js
- ...
Steps to reproduce:
ng lint
Exception stacktrace:
[error] Error: Decorator of type MemberExpression not yet handled
Occurred while linting /home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/src/lib/http-client.ts:78
at nameOfDecorator (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:483:13)
at Array.map (<anonymous>)
at positionDecorator (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:165:38)
at MethodDefinition[decorators.length=1]:exit (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:152:7)
at /home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
at NodeEventGenerator.applySelectors (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
at NodeEventGenerator.leaveNode (/home/sviat/IdeaProjects/front-polis-api/drivers/angular-driver/node_modules/eslint/lib/linter/node-event-generator.js:345:14)
Fail when linting next line:
class APIHttpClientAdapter {
protected static intercept<T extends APIHttpClientAdapter>(
target: T,
propertyKey: keyof T,
descriptor: TypedPropertyDescriptor<(options: BaseOptions) => Observable<APIHttpEvent>>,
): void {
...
}
}
export class APIAngularDriverHttpClient extends APIHttpClientAdapter {
@APIHttpClientAdapter.intercept // -> fail when linting current line
public get(requestOptions: APIHttpGetOptions): Observable<APIHttpEvent> {
...
}
}
After adding decorator-position plugin to my app eslint stopped working with an error like below:
ESLint: 7.9.0
Error: Error while loading rule 'decorator-position/decorator-position': .eslintrc.js » plugin:example/base:
Configuration for rule "camelcase" is invalid:
Value {"properties":"never","ignoreDestructuring":false,"ignoreImports":false,"ignoreGlobals":false} should NOT have additional properties.
Occurred while linting /Users/artemz/src/eslint-issue/main-app/.eslintrc.js
at validateRuleOptions (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/shared/config-validator.js:132:19)
at Object.keys.forEach.id (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/shared/config-validator.js:187:9)
at Array.forEach (<anonymous>)
at validateRules (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/shared/config-validator.js:184:30)
at validateConfigArray (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/shared/config-validator.js:312:9)
at CascadingConfigArrayFactory._finalizeConfigArray (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:464:13)
at CascadingConfigArrayFactory.getConfigArrayForFile (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/cli-engine/cascading-config-array-factory.js:275:21)
at CLIEngine.getConfigForFile (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/node_modules/eslint/lib/cli-engine/cli-engine.js:933:14)
at lineLength (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:327:35)
at Object.decoratorPositionRule [as create] (/Users/artemz/src/eslint-issue/node_modules/eslint-plugin-decorator-position/lib/rules/decorator-position.js:138:27)
error Command failed with exit code 2.
If I remove the plugin or the camelcase
rule configuration the error goes away.
I created a reproduction repo to play around with the configuration.
PS The file it tries to lint eslint-issue/main-app/.eslintrc.js
is not specific - reconfiguring the rule to be applied to files with another filter (*.ts for instance) yields the same result.
I have this code:
module('...', function () {
module('...', function (hooks) {
class Scenario {
@queryParam('strongest-avenger', { defaultValue: 'Thor' })
strongestAvenger: string | undefined;
}
The decorator would normally be inline, if there were no args.:
module('...', function () {
module('...', function (hooks) {
class Scenario {
@queryParam strongestAvenger: string | undefined;
}
so I think the inline vs above positioning needs to consider this decorator-factory pattern.
In my code prettier is doing multi-line because the decorator + property line exceeds the printWidth
In Discourse, we have a handful of property decorators like this:
// decorator-position ❌
class Blah {
@tracked somePropertyName =
this.some.long.property.which.extend.beyond.printWidth;
}
Prettier breaks this onto two lines, and keeps the @tracked somePropertyName
'inline', which is great. We'd like to keep this formatting.
Unfortunately the decorator-position
eslint rule fails. It wants to move the decorator onto a line by itself, leaving us with this:
// decorator-position ✅
class Blah {
@tracked
somePropertyName =
this.some.long.property.which.extend.beyond.printWidth;
}
A similar problem can be demonstrated with ternary expressions:
// decorator-position ❌
class Blah {
@tracked somePropertyName = this.someBoolean
? "resultIfTrue"
: "thisIsTheValueIfFalse";
}
// decorator-position ✅
class Blah {
@tracked
somePropertyName = this.someBoolean
? "resultIfTrue"
: "thisIsTheValueIfFalse";
}
Interestingly, multi-line function invocations seem to be accepted by the rule:
// decorator-position ✅
class Blah {
@tracked somePropertyName = this.someFunction(
"argumentValueOne",
"argumentValueTwo"
);
}
Would it be possible to have the decorator-position
rule accept the two ❌ cases described above?
Angular makes use of many decorators. It'd be great to add a default configuration that supports whatever idiomatic Angular is
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.