Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ideas for resources (resx) analyzers #3525

Closed
Evangelink opened this issue Apr 20, 2020 · 8 comments · Fixed by #3914
Closed

Ideas for resources (resx) analyzers #3525

Evangelink opened this issue Apr 20, 2020 · 8 comments · Fixed by #3914

Comments

@Evangelink
Copy link
Member

Add a new analyzer for roslyn-analyzers that will check for resources keys and values.

Rules for keys

  1. Key should end with Title, Message, Description or CodeFixTitle.

Rules for values

  1. If the value is linked to a title or message key, then it shouldn't end with a period '.'.

  2. If the value is linked to a description, it should end with a period '.'.

  3. Placeholders should be surrounded with single-quotes.

Tagging @mavasani for other ideas.

@Evangelink
Copy link
Member Author

Regarding keys, for rules with different messages, the current pattern is MessageSomeText and MessageSomeOtherText, could we use something else that would make it easier to have an automated detection? Like Message_SomeText or SomeTextMessage?

The analyzer could also be checking for [Something] or [SomethingAttribute] and report on it as this is a C# syntax.

@mavasani
Copy link
Contributor

mavasani commented Apr 20, 2020

@Evangelink - do you think the rule for keys would be possible to enforce? Do we foresee resource strings outside these 4 buckets? The core concern for me is that it would not be possible to add a source suppression for these cases as it is defined in a resx file.

@mavasani
Copy link
Contributor

@Evangelink - I'd say lets start with the analyzer that enforces what you suggested for rule values for now.

@Evangelink
Copy link
Member Author

@mavasani What about reporting on calling site instead of resource definition?

@mavasani
Copy link
Contributor

What about reporting on calling site instead of resource definition?

Ah, that seems to be a good idea :) Please do add a good description, and if possible a code fix. I am presuming you would anyways need such an analyzer to require the resx file passed in as an additional file so you can have code fixes that automatically fix the issue instead of manual fixes.

@mavasani
Copy link
Contributor

@Evangelink Feel free to get started here. Note that analysis of resx files is a pretty desired bucket of rules. For example, finding duplicate resx strings, flagging unused resx strings, etc. would be super helpful as well.

@Evangelink
Copy link
Member Author

@mavasani It'd be nice if we could define the next steps for this analyzer, it seems to be pretty important.

@mavasani
Copy link
Contributor

Yeah, hoping to get to it this week...

mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Jul 27, 2020
Closes dotnet#3525
Adds a code fix for RS1031, RS1032 and RS1033
Additionally, if the resx file with analyzer resource strings is provided as an additional file to the analyzer, also validates the strings in the resx file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants