Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

"requireTrailingComma: true" + "disallowTrailingComma: true" + autofix toggles comma #1905

Closed
jamietre opened this issue Oct 21, 2015 · 7 comments
Labels

Comments

@jamietre
Copy link

test.js:

var x = {
    a: 1,
    b: 2,
};

.jscsrc

{
    "disallowTrailingComma": true
}

Then

> jscs test.js --fix

(comma is removed)

> jscs test.js --fix

(comma is added again)

@markelog
Copy link
Member

Can't repro, @hzoo could you confirm?

@hzoo
Copy link
Member

hzoo commented Oct 22, 2015

Yeah I can't repro either actually. @jamietre Can you check again? And what version are you using?

@jamietre
Copy link
Author

Interesting.. I even set up the simple scenario just as in this report to verify it. Fresh install from npm public registry yesterday. I am on windows in full disclosure. Will try it in ubuntu vm today and see if I can repro shortly.

@jamietre
Copy link
Author

Here's the issue... apparently I didn't actually use that .jscsrc, this should repro it:

{
    "preset": "node-style-guide",
    "disallowTrailingComma": true,
}

or this (though this is obviously a silly config, but more clearly reveals the issue)

{
    "requireTrailingComma": true,
    "disallowTrailingComma": true,
}

It seems like there's a conflct with the previous requireTrailingComma directive. If you add "requireTrailingComma": false when using the preset, then it works.

Not sure if this is a general problem or specific to this rule, but it seems like any disallow rule should invalidate a previous require rule and vice-versa.

@jamietre jamietre changed the title "disallowTrailingComma: true" + --fix toggles trailing commas "requireTrailingComma: true" and "disallowTrailingComma: true" in same config with autofix toggles trailing commas Oct 22, 2015
@jamietre jamietre changed the title "requireTrailingComma: true" and "disallowTrailingComma: true" in same config with autofix toggles trailing commas "requireTrailingComma: true" + "disallowTrailingComma: true" + autofix toggles comma Oct 22, 2015
@hzoo
Copy link
Member

hzoo commented Oct 22, 2015

I think we would want to keep rules mostly independent of each other.
Although with 3.0 we should combine require/disallow like in #698 so this won't be an issue.

It's a general issue but the point is that normally you disable the rules in a preset so I would do "requireTrailingComma": false like you mentioned. http://jscs.info/overview#preset
Basically when using a preset you would first run the preset, and disable the rules in the preset and then add the required rules (at least for now)

Thanks for pointing it out though.

@lf94
Copy link

lf94 commented Feb 9, 2016

If this could be added to the "disableTrailingComma" documentation that would be fantastic. I wasted an hour trying to figure out what was going on.

@markelog
Copy link
Member

markelog commented Feb 9, 2016

@lf94 do you wanna do it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants