Coder Social home page Coder Social logo

matlabcodeanalyzer's Introduction

Hi, I'm Bastian, dad, hobby photographer, software developer, and signal processing scientist in Germany.

Both photography and programming are about telling stories. Expressing a complex algorithm in simple terms, or stunning vista in a compelling picture. Finding order and simplicity in a chaotic scene or code base. Therein lies the challenge and joy of life.

matlabcodeanalyzer's People

Contributors

bastibe avatar slootsjj avatar ssordopalacios avatar stdout-se avatar

Stargazers

 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

matlabcodeanalyzer's Issues

&&... makes check throw an error

Using latest commit from master (fc93e9a) and Matlab 2017b:

check with throw an error when checking lines that ends with compact statements, e.g. &&... or ||....

Steps to reproduce:

  • Create a new file testDots.m and paste the following:
function third = testDots()
    % TESTDOTS tests dots immediately following something else
    first = true;
    second = false;
    
    third = first &&...
        second;
end
  • Run check testDots.m
  • The following output is produced:
>> check testDots.m
Error using tokenize_code (line 123)
unknown operator '&&...'

Error in check (line 47)
    tokens = tokenize_code(source_code);

Expected behaviour:

  • A warning that there should be a space between && and ...

Switch statements cause "incorrect indentation" warnings

Using latest commit from master (fc93e9a) and Matlab 2017b:

When running check on a switch statement, it will warn about incorrect indentation for the case lines.

Steps to reproduce:

  • Create a new file testSwitch.m and paste the following (which has been auto-indented by Matlab 2017b)
function output = testSwitch()
% TESTSWITCH is a function to demonstrate false "incorrect indentation"
% warnings. Returns OUTPUT.

randomInt = 2; % Decided by fair dice roll

switch(randomInt)
    case 1
        output = 1;
    case 2
        output = 2;
    case 3
        output = 3;
    otherwise
        output = 'four'; % Uh oh, unlucky number
end
end
  • Run check testSwitch.m
  • The following output is produced:
>> check testSwitch.m
Code Analysis for testSwitch.m

  Required files: testSwitch.m
  Required toolboxes: MATLAB

  Function testSwitch (Line 1, col 19):

    Number of lines: 17 (good)
    Number of function arguments: 0 (good)
    Number of used variables: 2 (good)
    Max level of nesting: 2 (good)
    Code complexity: 4 (good)

    Line 8, col 1: incorrect indentation
    Line 9, col 1: incorrect indentation
    Line 10, col 1: incorrect indentation
    Line 11, col 1: incorrect indentation
    Line 12, col 1: incorrect indentation
    Line 13, col 1: incorrect indentation
    Line 14, col 1: incorrect indentation
    Line 15, col 1: incorrect indentation

Expected behaviour:

  • No warnings about incorrect indentation

Input/property validation using function argument validation routine not supported

Starting from MATLAB R2019b it is possible to:

  • use an arguments block for input validation.
  • use class, size and validation functions to validate property values.

Issue:

  • The argument validation is not recognized.
  • Validation routines are currently interpreted as a command, which interprets these class, size and validation functions as strings, leading to misinterpretation.

'newline' vs 'linebreak'

I was wondering why blocks of code that were definitely functions were being classified as scripts. In Line 46 of analyze_file.m, 'newline' should be 'linebreak'. That cleans up quite a bit.

Double quotes (") makes check throw an error

Using latest commit from master (fc93e9a) and Matlab 2017b:

check with throw an error when checking lines that contain double quotes (").

Steps to reproduce:

  • Create a new file testQuotes.m and paste the following:
echo("Hello");
  • Run check testQuotes.m
  • The following output is produced:
>> check testQuotes.m
Error using tokenize_code (line 200)
unknown identifier

Error in check (line 47)
    tokens = tokenize_code(source_code);

Expected behaviour:

  • It should not throw an error. Maybe a warning depending on settings?

Bugifx pattern matching in get_function_stats

MATLAB 2019a added a word to mlintInfo.message, so the regexp call on the current pattern returns an empty cell array. This then breaks the main function call since str2double cannot operate on an empty cell.

This is a problem I initially mentioned in #2. I propose replacing the existing pattern, which hard codes the whole line, with this: pattern = '''(?<f>[^'']+)'' is (?<n>[0-9]+)';

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.