SonarSource / SonarJS

SonarSource Static Analyzer for JavaScript and TypeScript
https://community.sonarsource.com/
GNU Lesser General Public License v3.0
1.05k stars 183 forks source link

Support trailling comma in tsconfig #1608

Closed saberduck closed 5 years ago

saberduck commented 5 years ago

Currently, we parse tsconfig using Java Gson parser, which doesn't support trailing commas. As a consequence we will be not able to assign files to projects using such tsconfig.

We should use TypeScript API to parse tsconfig. We will need new endpoint to sent the tsconfig file to eslint-bridge and receive list of files belonging to the project.

saberduck commented 5 years ago

we can use the API we used in SonarTS https://github.com/SonarSource/SonarTS/blob/0bac2c4253dcad38489025ca5fd4a70a9d9babfa/sonarts-core/src/utils/parser.ts#L87

thw0rted commented 4 years ago

The tsconfig file is read by a custom parser that also supports comments. From that same post, tsc --init generates a file that includes comments so it would make sense to avoid flagging comments as an error.

Should I open a new issue for this? Alternately, is there an easy way to configure my Sonar project to treat tsconfig(.*).json as JSONC instead of strict JSON?

saberduck commented 4 years ago

@thw0rted sorry, I don't follow. We use tsc to parse tsconfig.json, so we should be able to parse it normally. Please create a post on https://community.sonarsource.com/ and describe the problem you have.

thw0rted commented 4 years ago

Oh I get it now, this issue is about actually reading options from the tsconfig, not about analyzing tsconfig.json in user sources.

My point was that Sonar is flagging "issues" in tsconfig.json, in my source code, as though it were vanilla JSON. I wanted to suggest that Sonar should treat tsconfig.json as a special case, either as JSONC / JSON5, or maybe just special handling in the JSON checker based on filename. Is the Discourse you linked to the right place to bring that up?

vilchik-elena commented 4 years ago

@thw0rted it looks like you have problems with JSON analysis, not TypeScript. SonarSource does not provide analysis for JSON files, so probably you are using some third-party plugin. You should report your problems to them.

thw0rted commented 4 years ago

Thanks for the guidance, @vilchik-elena . The rule that's flagging (json:S2260) appears to come from Quality Profile "SonarQube Way", under "JSON". It says "This quality profile is provided by a plugin." I've looked at every link I can find in the interface but I cannot figure out how to list the installed plugins on this server. (I am not an admin.)

Since I don't know what plugin provides it, I don't know where to give feedback. I know this isn't the best place to get support, but after some Googling I still can't figure out where a non-privileged Sonar user can find the list of installed plugins on a server, or the specific name of the plugin that provides a quality profile. Help?

vilchik-elena commented 4 years ago

a wild guess https://github.com/racodond/sonar-json-plugin ?:)

thw0rted commented 4 years ago

I found that, and it was my guess too. But, teach me to fish here -- is there really no way for me to confirm that they're definitely using this plugin, given that I'm not a server admin? It seems like every user should be able to see what plugins are running (and ideally what version), specifically for the situation I'm in now, where I want to understand what's happening and why.

vilchik-elena commented 4 years ago

try <server url>/deploy/plugins/index.txt, you will get the names of plugin files (usually with versions), but it does not provide you with the producer of the plugin.

thw0rted commented 4 years ago

Sweet! I see sonar-json-plugin-2.2.jar on that list, which does in fact belong to the repo you linked. Thanks again!