Giter Club home page Giter Club logo

florianschanda / miss_hit Goto Github PK

View Code? Open in Web Editor NEW
148.0 9.0 21.0 4.25 MB

MATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more

License: GNU General Public License v3.0

Python 48.94% MATLAB 10.69% M 0.24% Makefile 0.13% Mathematica 0.01% HTML 39.39% C 0.01% Shell 0.01% Objective-C 0.01% Limbo 0.01% JavaScript 0.01% CSS 0.41% Mercury 0.01% Scilab 0.15%
matlab static-analyzer formal-methods octave parser lexer style-checker linter code-formatter python3

miss_hit's People

Contributors

17as avatar florianschanda avatar j-r-jones avatar remi-gau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miss_hit's Issues

New rule: Continuing lines should not start with operator

In multi-line statements, continuing lines should not start with an operator (+, *, &&, etc)
Desired syntax:

x = a + b + ...
    c + d;
x = (a || b) && ...
    (c || d);

Undesired syntax:

x = a + b ...
    + c + d;
x = (a || b) ...
    && (c || d);

support persistent

https://uk.mathworks.com/help/matlab/ref/persistent.html

persistent var1 ... varN declares variables var1 ... varN as persistent. Persistent variables are local to the function in which they are declared, yet their values are retained in memory between calls to the function. Code at the MATLAB (R) command line and in other functions cannot change persistent variables.

When MATLAB (R) first encounters a particular persistent statement, it initializes the persistent variable to an empty matrix ([]).

support Octave language features different from MATLAB

support command_form

Stuff like cd potato is currently special cased, but it shouldn't be. Right now it breaks if you use a continuation in such a command.

https://www.mathworks.com/help/matlab/matlab_prog/command-vs-function-syntax.html

load durer.mat        % Command syntax
load('durer.mat')     % Function syntax

All functions support this standard function syntax:

[output1, ..., outputM] = functionName(input1, ..., inputN)

If you do not require any outputs from the function, and all of the inputs are character vectors (that is, text enclosed in single quotation marks), you can use this simpler command syntax:

functionName input1 ... inputN

With command syntax, you separate inputs with spaces rather than commas, and do not enclose input arguments in parentheses. Command syntax always passes inputs as character vectors. To use strings as inputs, use the function syntax. If a character vector contains a space, use the function syntax. For example:

When a function input is a variable, you must use function syntax to pass the value to the function. Command syntax always passes inputs as character vectors and cannot pass variable values. For example, create a variable and call the disp function with function syntax to pass the value of the variable:

A = 123;
disp(A)

This code returns the expected result,

123

You cannot use command syntax to pass the value of A, because this call

disp A

is equivalent to

disp('A')

and returns

A

New rule: Space before inline comment

Inline comments should have a space before the start of the comment
Desired syntax:

x = a + b; % Some comment
y = a + b + ... Another comment
    c + d;

Undesired syntax

x = a + b;% Some comment
y = a + b +... Another comment
    c + d;

autofix indentation

Related keywords should have the same indentation as the line starting the code body. Mostly this is relevant for the end keyword but elseif and else should also be aligned with their matching if.
Example of desired syntax:

function u = fcn(x)
    z = x + 3;
    if z > 7
        y = 'a';
    else
        y = 'b';
    end

    switch y
        case 'a'
            u = true;
        case 'b'
             u = false;
    end
end

Include/exclude rules

It would be good to enable/disable rules via config files. For example

remove_rule: "Foo_Rule"
remove_rule: "Bar_Rule"

And maybe later

restore_rule: "Foo_Rule"

New rule: No use of true, false, pi etc as variable names

In Matlab, some keyword-like words can be used without prior assignment or definition, but they can also be assigned a value. The most obvious ones are true, false, pi, exp and eps (technically pi, exp and eps are built-in functions but they have such specific meanings that there is no reasonable use case where assignment to them is necessary). Assigning something to these keywords can introduce severe, hard-to-find bugs.
Example

false = 0.01;
if false % Will evaluate to true since false has been assigned
    % Do something
end

A rule should be introduced to prevent assignment to certain variable names with =.

Implement FunctionName rule

Easy if naming is consistent, kinda needs parsing if naming depends on scope (e.g. different scheme for class methods).

  • regex for functions
  • regex for methods
  • regex for nested functions (same as functions by default)

nested functions

https://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html
https://www.mathworks.com/help/matlab/matlab_prog/variables-in-nested-and-anonymous-functions.html

function parent
disp('This is the parent function')
nestedfx

   function nestedfx
      disp('This is the nested function')
   end

end
  • Nested functions can use variables that are not explicitly passed as input arguments.
  • In a parent function, you can create a handle to a nested function that contains the data necessary to run the nested function.
  • To nest any function in a program file, all functions in that file must use an end statement.
  • You cannot define a nested function inside any of the MATLAB® program control statements, such as if/elseif/else, switch/case, for, while, or try/catch.
  • All of the variables in nested functions or the functions that contain them must be explicitly defined. That is, you cannot call a function or script that assigns values to variables unless those variables already exist in the function workspace.

Add wildcard/regex path disables

Lets say you want to disable e.g. foo/*/autogen/*, then right now you need to update your code generator to also generate a miss_hit.cfg.

It might be nice to have a way to do this without relying on the cooperation of your code generators.

better formatting for html report

  • It would be nice to use some heading tags to separate files from each other in the report
  • it would be nice to make only the file/line a link, and leave the message as plaintext

New rule: "Whitespace before ..."

Line continuation (...) should always be preceded by a whitespace in code

Example

x = a + b +...
    c + d

should instead be

x = a + b + ...
    c + d

Add --octave option

To enable support for octave specific things, such as:

  • # comments
  • function parameter default values
  • ++ and += style operations
  • \ line continuation
  • etc.
    (This ticket is about only the option and octave-style comments.)

complex for

For iterating over a matrix as opposed to a : expression

resolve minor issues with HTML report

Some issues need fixing:

  • miss_hit.m should actually pass style checking ;)
  • css should be embedded in the HTML so that relative paths won't be an issue
  • add check in main program to make sure options.html is a file or not existing (otherwise you get a crash if it's a directory). also make sure if any directory is provided, it exists (os.path.dirname helps).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.