Description of rule javascript:S1192 exceptions is vague

Some confusion in the description ( SonarQube ) about exceptions:

  1. “The same goes for statement-like string literals, e.g. 'use strict';.” – Most exception lists are explicit and complete; could we have one here, if it’s not too long?
  2. Unclear about interaction between ignoreStrings parameter and built-in ignores: is the parameter just added to the built-in list? If I delete the parameter (or set it blank) do I still have the built-in exceptions?

Hello @MisterPi,

The ignoreStrings parameter is additive to the built-in exceptions. It doesn’t replace them. ignoreStrings provides a comma-separated list of specific string values to ignore regardless of context.

The built-in exceptions is not a hardcoded list of strings, they are based on the AST shape:

  • ExpressionStatement: covers ‘use strict’ and any standalone string statements
  • TSLiteralType: type Status = 'pending' | 'done';
  • MemberExpression: obj['key']
  • ImportDeclaration: import paths
  • ImportExpression: dynamic imports
  • JSXAttribute
  • ExportAllDeclaration / ExportNamedDeclaration: export paths
  • require() calls
  • Object property keys: const obj = {'some-key': value};

The reasoning behind allowing any standalone string statement is that usually that would already raise S905. That rule has an exception to ignore directives like use strict;. About what is a directive and what is not, it’s not so clear. Usually, parsers will mark as directive any standalone string statement at the beginning of the code as directive, no matter what the string contents are. We rely on that exact logic, so use string; is never handled specifically.

I hope this makes things clear.

Cheers!

Thanks! I was just suggesting that the exceptions should be listed in the rule, as they are, for instance, here: SonarQube

2 Likes

Hi @MisterPi,

thanks for the feedback. I created a PR to list the exceptions.

Cheers!