Add linter test for ".replace('" |
||||
Issue descriptionIn CL https://codereview.chromium.org/2930833004 a quick fix for a bug used blah.replace('foo', 'bar') which was only a partial fix to the issue. This is because blah.replace('foo', 'bar') only replaces the first occurrence of 'foo' in blah. In the interest of avoiding similar issues in the future, consider adding a Lint test on javascript for “.replace(‘“ and advise “.replace(/.../g” instead.
,
Jul 20 2017
Also, not sure if flagging all usage of replace() to use /g is a good solution. There can be legitimate usages of replace() to only replace the 1st occurrence. Demanding unit tests for the code that uses replace(), during code review seems more scaleable I think.
,
Jul 20 2017
dpapad@ discussed this further offline. The goal is to have something automated that advises SWEs about the potential to misunderstand .replace(). That doesn't have to be a linter test, but it needs to be more than having SWEs simply "do better", since the code did have unit tests that didn't cover that case (and the code and unit tests were reviewed by *very* experienced JavaScript SWEs). We also discussed whether expecting replace() to replace all occurrences would be a common case. I found that searching for why: javascript replace() only replaces the first instance, finds several help forum Q&As. There are 100's of combined upvotes on answers explaining this unexpected behavior. Certainly more research can be done, but there does seem to be an issue here.
,
Aug 4 2017
This is a not a PM-goal (as I initially thought it would be), so lessening the pri.
,
Jan 10
Archiving P3s older than 1 year with no owner or component. |
||||
►
Sign in to add a comment |
||||
Comment 1 by dpa...@chromium.org
, Jul 20 2017