Tslint: Cannot disable object-literal-sort-keys when extending tslint:recommended

Created on 12 Mar 2018  ·  6Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.7.1
  • __Running TSLint via__: CLI

TypeScript code being linted

export const testState = {
  "user": {
    "is_moderator": true,
    "moderated_archives": [    ],
    "username": "rrrrr",
    "is_admin": false,
    "name": "rrrrr",
    "moderated_categories": [
    ],
  },
  "num_submissions_with_actionable_proposals": 6,
  "last_queue_view": "2018-02-09 13:58 EST",
  "publish_times": {
    "submitted": "2018-02-11 20:00 EST",
    "next": "2018-02-12 20:00 EST",
  },
  "current_time": "2018-02-09 13:59 EST",
  "queue": []
}

with tslint.json configuration:

{
    "extends": ["tslint:recommended"],
    "rules": {
        "object-literal-sort-keys": false    
    }
}

Actual behavior

bdc34 @bdc34-laptop: modui-typescript$ cat tslint2.json
{
"extends": ["tslint:recommended"],
"rules": {
"object-literal-sort-keys": false
}
}bdc34 @bdc34-laptop: modui-typescript$ ./node_modules/.bin/tslint --config ./tslint2.json -p ./ | grep 'is not sorted'
ERROR: /home/bdc34/src/arxiv-submit/modui-typescript/src/model/testData.js[9, 5]: The key 'is_admin' is not sorted alphabetically
ERROR: /home/bdc34/src/arxiv-submit/modui-typescript/src/model/testData.js[24, 3]: The key 'num_submissions_with_actionable_proposals' is not sorted alphabetically
ERROR: /home/bdc34/src/arxiv-submit/modui-typescript/src/model/testData.js[28, 5]: The key 'next' is not sorted alphabetically
ERROR: /home/bdc34/src/arxiv-submit/modui-typescript/src/model/testData.js[35, 7]: The key 'doi' is not sorted alphabetically

Expected behavior

No errors for literal keys out of order.

Most helpful comment

Sorry, I see that I needed JsRules:

"jsRules":{
    "object-literal-sort-keys": false,
}

All 6 comments

Sorry, I see that I needed JsRules:

"jsRules":{
    "object-literal-sort-keys": false,
}

I still find this to not be completely solved.

{
  "extends": ["tslint:recommended"],
  "rules": {
    "object-literal-sort-keys": false
  },
  "jsRules": true
}

This does not work - but I think that it should. We are extending tslint:recommended, overwriting a rule, and then saying we want all rules to also apply to JS (those that can). But this doesn't work for me.

I need to explicitly add the rule again:

{
  "extends": ["tslint:recommended"],
  "rules": {
    "object-literal-sort-keys": false
  },
  "jsRules": {
    "object-literal-sort-keys": false
  }
}

As per the documentation on jsRules:

jsRules?: any | boolean: Same format as rules or explicit true to copy all valid active rules from rules. These rules are applied to .js and .jsx files.

@lostpebble we are tracking that issue with jsRules: https://github.com/palantir/tslint/issues/4513

Yea jsRules doesn't work:

Could not find implementations for the following rules specified in the configur ation:                                                                               jsRules                                                                      Try upgrading TSLint and/or ensuring that you have all necessary custom rules in stalled.                                                                         If TSLint was recently upgraded, you may have old rules configured which need to  be cleaned up.
--

I just get an error when trying to set it even though I'm on the latest tslint.

if should be beneath rules, not the jsRules - most appreciated answer from Author is no longer correct.

image

🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

Was this page helpful?
0 / 5 - 0 ratings