florianschanda / miss_hit

MATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more
GNU General Public License v3.0
158 stars 21 forks source link

Redundant spaces after various characters are not removed #272

Open migjc opened 1 year ago

migjc commented 1 year ago

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 commented 1 year ago

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