florianschanda / miss_hit

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

new rule: imports, globals and persistent before code #120

Open niklasnylen opened 4 years ago

niklasnylen commented 4 years ago

What kind of feature is this?

MISS_HIT component affected

Describe the solution you'd like Global and persistent variables shall be declared first in functions.

florianschanda commented 4 years ago

However they need to be after any argument validation blocks, so a function should be ordered like this:

  1. Argument validation blocks (only in matlab 2019b)
  2. imports
  3. global
  4. persistent
  5. function body
  6. nested functions
florianschanda commented 3 years ago

@niklasnylen an update this ticket (and similar ones that would do code re-structuring beyond adding whitespace and deleting stuff).

I plan to create another tool mh_reformat that is a much more advanced code reformatting tool. It does not produce messages like mh_style; but instead just pretty prints code.

I suspect I will also remove the autofixing from mh_style once this works. In the future mh_style will only complain :)

The reason for this is largely technical / and developer (i.e. me) sanity. The code that does the fixing has become so complicated that adding new functionality is just not practical any more. :/