pinterest / arcanist-linters

A collection of custom Arcanist linters
Apache License 2.0
62 stars 45 forks source link

Add multibyte (unicode) safety and key check fix #81

Closed RainNapper closed 3 years ago

RainNapper commented 3 years ago

1) Update substrings to be resolved using mb_substr instead of substr in case the input text is unicode.

2) Add isset check before resolving 'fix' index in the offense. This is throwing an error on every linter without a fix.

Tested by making local changes with unicode strings and verifying the fix was applied as expected:

Before fix

[2021-06-23 05:56:35] ERROR 8: Undefined index: fix at [[repo]/.pinterest-linters/src/ESLintLinter.php:168]
arcanist(), phutil(), pinterest-linters(head=[branch], ref.master=029aa63c3ef7, ref.[branch]=9c6778333e2a)
  #0 ESLintLinter::parseLinterOutput(string, integer, string, string) called at [<arcanist>/src/lint/linter/ArcanistExternalLinter.php:437]
  #1 ArcanistExternalLinter::resolveFuture(string, ExecFuture) called at [<arcanist>/src/lint/linter/ArcanistFutureLinter.php:34]
  #2 ArcanistFutureLinter::didLintPaths(array) called at [<arcanist>/src/lint/engine/ArcanistLintEngine.php:605]
  #3 ArcanistLintEngine::executeDidLintOnPaths(ESLintLinter, array) called at [<arcanist>/src/lint/engine/ArcanistLintEngine.php:556]
  #4 ArcanistLintEngine::executeLintersOnChunk(array, array) called at [<arcanist>/src/lint/engine/ArcanistLintEngine.php:484]
  #5 ArcanistLintEngine::executeLinters(array) called at [<arcanist>/src/lint/engine/ArcanistLintEngine.php:216]
  #6 ArcanistLintEngine::run() called at [<arcanist>/src/workflow/ArcanistLintWorkflow.php:337]
  #7 ArcanistLintWorkflow::run() called at [<arcanist>/scripts/arcanist.php:394]
>>> Lint for [file].js
   Error  (ESLINT) no-unused-vars
    'hahaha' is assigned a value but never used.

              77     ;
              78 
              79 
    >>>       80   const hahaha = "✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split     (
                         ^
              81     ","
              82   );
              83 

   Auto-Fix  (ESLINT) prettier/prettier
    Replace `"✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split·····(⏎····","⏎··`
    with `'✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️'.split(','`

              77     ;
              78 
              79 
    >>> -     80   const hahaha = "✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split     (
        +          const hahaha = '✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️'.split(',Ắ✂️✂️,✂️✂️✂️✂️".split     (
              81     ","
              82   );
              83 
              84   const loadImage = useCallback(async () => {

After fix:

>>> Lint for [file].js
   Error  (ESLINT) no-unused-vars
    'hahaha' is assigned a value but never used.

              77     ;
              78 
              79 
    >>>       80   const hahaha = "✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split     (
                         ^
              81     ","
              82   );
              83 

   Auto-Fix  (ESLINT) prettier/prettier
    Replace `"✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split·····(⏎····","⏎··`
    with `'✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️'.split(','`

              77     ;
              78 
              79 
    >>> -     80   const hahaha = "✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️".split     (
        -     81     ","
        -     82   );
        +          const hahaha = '✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️✂️✂️,✂️✂️✂️✂️'.split(',');
              83