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

Redundant spaces after various characters are not removed #272

Open
migjc opened this issue Jun 19, 2023 · 1 comment
Open

Redundant spaces after various characters are not removed #272

migjc opened this issue Jun 19, 2023 · 1 comment
Labels
tool: mh_style Affects the style checker tool

Comments

@migjc
Copy link

migjc commented Jun 19, 2023

MISS_HIT Component affected: Style checker
Environment: MATLAB R2022b
System: Windows
Python: Python 3.10.4

While it is enforced by several rules that there must be a whitespace before / after certain tokens, it should also be enforced that there is only one. E.g.:
The line
if ~strcmp(valid,'Valid')
is fixed to
if ~strcmp(valid, 'Valid')
(adding the missing space), but
if ~strcmp(valid, 'Valid')
is not touched at all and not marked as an style issue. Another constructions that have the same problem:

if conditionA && conditionB
myVar = 25 / 14;

My guess is that this is a generalized thing. It also happens when tabs are replaced. The tabs are converted to tabwidth spaces, but then these extra spaces are left behind. E.g.:
myVar = 25 /\t14;
is transformed into
myVar = 25 / 14;

After having a quick look at the code, if I were to fix this I would start by changing the implementation of all the whitespace rules to ensure that there is one (and only one) whitespace.

Another option, probably a bit more "brute force", would involve removing all instances of more than 1 space in the code at the beginning of the style checks, normalizing all text to use a single whitespace character. Then, the code that does the alignment can add extra spaces wherever is right, at the beginning of a line.

Note: I would be happy to work on a fix, but thought of reporting first in case the approach is not optimal or there are better suggestions.

@florianschanda
Copy link
Owner

This was kinda intentional, to allow people to do horizontal layout, e.g.

[1, 500
 2,   0]

We could have a better or configurable rule that lays things out better

@florianschanda florianschanda added the tool: mh_style Affects the style checker tool label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool: mh_style Affects the style checker tool
Projects
None yet
Development

No branches or pull requests

2 participants