florianschanda / miss_hit Goto Github PK
View Code? Open in Web Editor NEWMATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more
License: GNU General Public License v3.0
MATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more
License: GNU General Public License v3.0
https://uk.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html
f = @myfunction;
fhandle = @(x,y) x.^2 + y.^2;
{@(x) 2}
https://uk.mathworks.com/help/matlab/matlab_oop/calling-superclass-methods-on-subclass-objects.html
disp@MySuper(obj)
obj = obj@MySuper(arg1,arg2,...)
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 =
.
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);
https://uk.mathworks.com/help/parallel-computing/spmd.html
spmd
statements
end
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.
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
Some issues need fixing:
miss_hit.m
should actually pass style checking ;)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).To enable support for octave specific things, such as:
#
commentsNon-script files (i.e. a function or class)
Hard, needs parsing
a = ['('];
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
It is possible (but stupid) to write stuff like @(~) 1
a < b < c
parses as (a < b) < c
which means 1 < x < 3
is always true, even for NaN.
https://www.mathworks.com/help/matlab/ref/i.html
1i
z = a + bi
z = x + 1i*y
Sadly the parse problems attached to imaginary numbers are quite real.
Easy if naming is consistent, kinda needs parsing if naming depends on scope (e.g. different scheme for class methods).
https://uk.mathworks.com/help/matlab/matlab_oop/class-components.html
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;
https://uk.mathworks.com/help/matlab/ref/import.html
import PackageName.ClassName
import PackageName.FunctionName
import PackageName.ClassName.staticMethodName
import PackageName.*
It's not really a keyword or a statement, but it's maybe best to treat it like one.
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
For iterating over a matrix as opposed to a : expression
Might need some parsing
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
https://uk.mathworks.com/help/matlab/ref/metaclass.html
mc = metaclass(object)
mc = ?ClassName
Trivial with parsing, annoying without.
https://uk.mathworks.com/help/matlab/ref/try.html
try
statements
catch exception
statements
end
https://uk.mathworks.com/help/matlab/ref/mlock.html
MATLAB (R) clears persistent variables when you clear or modify a function that is in memory. To keep a function in memory, use mlock
.
Trivial with minimal parsing
Maybe
No whitespace before :
except after ,
. Example: y = x(2, :)
No whitespace after :
. Examples: y = x(3, 1:end)
, x{:}
https://uk.mathworks.com/help/matlab/ref/parfor.html
parfor loopvar = initval:endval; statements; end
parfor (loopvar = initval:endval, M); statements; end
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"
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 ([]
).
Deal with "script" files
For example 10^-4
is currently a parse error
Pragmas in MATLAB are %#foo and should be supported as such
x.(expression)
Allow weird stuff like if x;
https://uk.mathworks.com/help/matlab/ref/switch.html
switch switch_expression
case case_expression
statements
case case_expression
statements
...
otherwise
statements
end
https://uk.mathworks.com/help/matlab/ref/end.html
For example, X(end)
is the last element of X
, and X(3:end)
selects the third through final elements of X
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.