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

object-literal-sort-keys and accented words #4167

Closed
rodrigojcmello opened this issue Sep 16, 2018 · 4 comments
Closed

object-literal-sort-keys and accented words #4167

rodrigojcmello opened this issue Sep 16, 2018 · 4 comments

Comments

@rodrigojcmello
Copy link

Bug Report

  • TSLint version: 5.11.0
  • TypeScript version: 3.0.3
  • Running TSLint via: VSCode

TypeScript code being linted

interface IAdicionarItem {
    autor: string; // these 3 items were sorted alphabetically by vscode (no tslint was used for this), here it is right.
    título: string; // i with accent 
    type: 'ADICIONAR_ITEM';
}

export const adicionarItem = (autor: string, título: string): IAdicionarItem => ({
    autor,
    título, // "i" with accent should still come before "y"
    type: 'ADICIONAR_ITEM', // [tslint] The key 'type' is not sorted alphabetically (object-literal-sort-keys)
});

with tslint.json configuration:

{
    "defaultSeverity": "warning",
    "extends": [
        "tslint:recommended",
        "tslint-react"
    ],
    "jsRules": {},
    "rules": {
        "quotemark": [
            true,
            "single",
            "jsx-single"
        ],
        "jsx-no-multiline-js": false,
        "jsx-no-lambda": false,
        "no-console": false
    },
    "rulesDirectory": []
}

Actual behavior

Words with accents must be in the end so there is no error / warning in TSLint

Expected behavior

Items should be sorted alphabetically considering accents without any TSLint error / warning

captura de tela 2018-09-16 as 11 18 32

@pe8ter
Copy link
Contributor

pe8ter commented Sep 27, 2018

Looks like JavaScript has some options for an easy win:

https://davidwalsh.name/sorting-strings-accented-characters
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

I could make a PR if this. I'd like to know if using localeCompare() for all sorting would be an acceptable solution, or if adding an option to use this as the sort function would be preferable.

@johnwiseheart
Copy link
Contributor

I think its probably preferable to add an option for this to avoid throwing errors on code that was previously "correct". In the next major version we can turn on the option by default.

@pe8ter
Copy link
Contributor

pe8ter commented Dec 18, 2018

@johnwiseheart
Copy link
Contributor

Since it’s been released, I think we can close this issue.

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

No branches or pull requests

4 participants