From 9f97a1ab2e64f41ddb94e5d24686edb659cfd811 Mon Sep 17 00:00:00 2001 From: Co Melissant Date: Thu, 25 Sep 2025 08:16:30 +0200 Subject: [PATCH 1/4] #1 first changes --- MATLAB-Coding-Guidelines.md | 64 +++++++++++-------------------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/MATLAB-Coding-Guidelines.md b/MATLAB-Coding-Guidelines.md index 8a7b536..43362e1 100644 --- a/MATLAB-Coding-Guidelines.md +++ b/MATLAB-Coding-Guidelines.md @@ -41,6 +41,18 @@ - [General](#general) - [Try-Catch](#try-catch) +# Deviations in this fork from the original MathWorks version +- This section. +- Removed discussion on detection of rule and best practice violations using plain MATLAB - as this version of the document is targeting CC4M users. +- Added [section](#detection-using-cc4m) on detection violations using CC4M. + + + + + # The Purpose of this Document As applications get larger and more complex, organizations are adopting more formal coding practices including code reviews, automated builds, and continuous integration. Organizations which develop applications involving teams of people writing MATLAB code want to introduce regularity and consistency in their code bases to enhance the quality of their MATLAB code. @@ -142,53 +154,13 @@ The table for each guideline has the following fields. - **History:** The version of this document when the guideline was introduced. -## Rules - -Rule violations are (or will be) detectable by the MATLAB Code Analyzer. The Code Analyzer is a tool in MATLAB that examines code to identify problems and make recommendations for improvement. It can identify issues related to syntax errors, compatibility, performance, deprecated functionality and much, much more. The Code Analyzer provides [over two thousand checks](https://www.mathworks.com/help/matlab/matlab_env/index-of-code-analyzer-checks.html) for various potential code issues. Those checks can be enabled, disabled, or customized by [creating a local codeAnalyzerConfiguration.json file](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html) similar to the example shown below. - - - -The MATLAB Code Analyzer can detect violations for a subset of the Rules listed in this document. Note that some versions of MATLAB may not be able to detect violations for all of the rules. When the Code Analyzer detects a Rule violation, it identifies the issue in both the MATLAB Editor and the Code Analyzer Report. Beginning in R2025a, violations in the Editor are indicated on the right-hand side of the Editor panel as shown in the following screenshot. - - - -This guidelines document is accompanied by a `codeAnalyzerConfiguration.json` file which implements the checks for the set of Rule violations that can be detected. - -The Code Analyzer check for any Rule can be disabled. Consider the example in the screenshot above. There is a Rule that specifies that function names must be lowercase or lowerCamelCase. You can disable this Rule if you want to turn off checking for function name casing. Most Rules can also be configured. In the case above, you could change the options for function name casing to use a different convention (e.g., UpperCamelCase). The Detection field in the Rule information table provides information about which Code Analyzer check is used to detect violations of the Rule. You can then disable or modify the check in your Code Analyzer Configuration file. - -## Best Practices - -Best Practices are simply recommendations for writing better MATLAB code. The information provided for a Best Practice is similar to that provided for a Rule. Below is an example Best Practice from the Guidelines. - -There are some Best Practices that can (optionally) be detected as Rules by enabling a check in the Code Analyzer. Most of those checks are disabled by default. Information on optional detection, when available, is shown in the **Detection** field of the information for a Best Practice. - -**Type:** Best Practice - -**Description:** Use cell arrays only to store data of varying classes and/or sizes. Do not use cell arrays to store character vectors as text data. Use a string array instead. - -**Motivation:** - -- Readability: Using string arrays instead of cell arrays of character vectors improves the readability of the code. +## Detection using CC4M -- Performance: String operations are more performant than operations on cell arrays of character vectors. - -**Allowed:** - -```matlab -data = {datetime "abc" 123}; -arrays = {rand(1,10) zeros(2,4) eye(5)}; -missions = ["Mercury" "Gemini" "Apollo"]; -``` - -**Not Allowed:** - -```matlab -missions = {'Mercury' 'Gemini' 'Apollo'}; -``` - -**Detection:** Optionally by enabling Code Analyzer check `DAFCVC` (R2024a) - -**History:** Introduced in Version 1.0 +Starting with CC4M version 2.20 a configuration is shipped that checks compatibility with this set of guidelines. +Why use CC4M? +- Using CC4M for detecting violations comes with a coverage of 58% of all guidelines (compared to 30% by using the MATLAB Code Analyzer) +- CC4M runs all checks in MATLAB R2017b and newer. +- Other valuable features and all available checks are described in the [documentation](https://doc.monkeyproofsolutions.nl/code-checker-for-matlab/code-checker-for-matlab/index.html). ## Definitions From fae3a2a5269ae95f84cf4826c8b3e8188d4c0e1c Mon Sep 17 00:00:00 2001 From: "co.melissant" Date: Tue, 14 Oct 2025 09:40:03 +0200 Subject: [PATCH 2/4] # ready for review --- MATLAB-Coding-Guidelines.md | 364 +++++++++++++++++++++++++++--------- 1 file changed, 271 insertions(+), 93 deletions(-) diff --git a/MATLAB-Coding-Guidelines.md b/MATLAB-Coding-Guidelines.md index 43362e1..3e2f319 100644 --- a/MATLAB-Coding-Guidelines.md +++ b/MATLAB-Coding-Guidelines.md @@ -41,10 +41,25 @@ - [General](#general) - [Try-Catch](#try-catch) -# Deviations in this fork from the original MathWorks version -- This section. -- Removed discussion on detection of rule and best practice violations using plain MATLAB - as this version of the document is targeting CC4M users. -- Added [section](#detection-using-cc4m) on detection violations using CC4M. +# Why this fork: use of CC4M + +## Detection using CC4M + +Starting with CC4M version 2.20 a configuration is shipped that checks compatibility with this set of guidelines. + +All guidelines of type "Rule" are assigned priority "Highly recommended" and all guidelines of type "Best practice" are assigned priority "Recommended". The objectives of the motivations are listed in the category. + +Why use CC4M for checking compliance with the MATLAB Guidelines? +- Using CC4M for detecting violations comes with a coverage of over 60% of all guidelines (compared to ~30% by using the MATLAB Code Analyzer) +- CC4M runs all checks in MATLAB R2017b and newer with the note that new features (like `arguments` block) are only checked for in the releases were the feature is available. +- The Violations report includes a link to the violated guideline, making the checking process a learning experiecne as well. +- Other valuable features and all available checks are described in the [documentation](https://doc.monkeyproofsolutions.nl/code-checker-for-matlab/code-checker-for-matlab/index.html). + +## Deviations from original + +- Removed discussion on detection of rule and best practice violations using MATLAB Code Analyzer - as this version of the document is targeting CC4M users. +- Added a [section](#detection-using-cc4m) on detection violations using CC4M. +- The "Detection" section of every guideline is expanded in case CC4M can detect violations. + + ## Definitions @@ -347,7 +407,9 @@ sin sqrt ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNameIsShadowing` **History:** Introduced in Version 1.0 @@ -380,7 +442,9 @@ significancePearsonGravitationalCorrelation percentROIAreaContainingPositivePixels ``` -**Detection:** Code Analyzer check `naming.variable.maxLength` (R2025a) +**Detection:** +- MLCA: Code Analyzer check `naming.variable.maxLength` (R2025a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNameLength` **History:** Introduced in Version 1.0 @@ -416,7 +480,9 @@ e = m*c^2 % c = speed of light color, colorGroup % pluralization ``` -**Detection:** Not detectable +**Detection:** +MLCA: Not detectable +CC4M: Not Detectable **History:** Introduced in Version 1.0 @@ -449,7 +515,9 @@ BTransform Greenwich_Mean_Time ``` -**Detection:** Code Analyzer check `naming.variable.regularExpression` (R2025a) +**Detection:** +- MLCA: Code Analyzer check `naming.variable.regularExpression` (R2025a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkVariableCasing` **History:** Introduced in Version 1.0 @@ -482,23 +550,18 @@ validateBlockPathForModelBlockNormalModeVisibility plotExactRectangularMembraneConstantLineLoad ``` -**Detection:** Code Analyzer checks (R2025a) - -- `naming.class.maxLength` - -- `naming.function.maxLength` - -- `naming.localFunction.maxLength` - -- `naming.method.maxLength` - -- `naming.nestedFunction.maxLength` - -- `naming.property.maxLength` - -- `naming.event.maxLength` +**Detection:** +- MLCA: Code Analyzer checks (R2025a) + - `naming.class.maxLength` + - `naming.function.maxLength` + - `naming.localFunction.maxLength` + - `naming.method.maxLength` + - `naming.nestedFunction.maxLength` + - `naming.property.maxLength` + - `naming.event.maxLength` + - `naming.enumeration.maxLength` +- CC4M: `monkeyproof.cc4m_checks.checkNameLength` (does not check the length for properties, events, fieldnames or enumerations) -- `naming.enumeration.maxLength` **History:** Introduced in Version 1.0 @@ -557,13 +620,12 @@ PRINTALL detect_features ``` -**Detection:** Code Analyzer checks (R2025a) - -- `naming.function.casing` - -- `naming.localFunction.casing` - -- `naming.nestedFunction.casing` +**Detection:** +- MLCA: Code Analyzer checks (R2025a) + - `naming.function.casing` + - `naming.localFunction.casing` + - `naming.nestedFunction.casing` +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkUserDefinedFunctionCasing` **History:** Introduced in Version 1.0 @@ -586,7 +648,9 @@ plot(x, y, LineWidth=2) surf(peaks, FaceColor="interp") ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkNameValuePairCasing` **History:** Introduced in Version 1.0 @@ -636,7 +700,9 @@ shapes.Polynomial % in a namespace ecgSignal % in the global namespace ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected. +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkClassCasing` **History:** Introduced in Version 1.0 @@ -684,7 +750,9 @@ startRecording registerDevice ``` -**Detection:** Code Analyzer check `naming.method.casing` (R2025a) +**Detection:** +- MLCA: Code Analyzer check `naming.method.casing` (R2025a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkMethodCasing` **History:** Introduced in Version 1.0 @@ -732,7 +800,9 @@ RelativeTolerance Visible ``` -**Detection:** Code Analyzer check `naming.property.casing` (R2025a) +**Detection:** +- MLCA: Code Analyzer check `naming.property.casing` (R2025a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkPropertyCasing` **History:** Introduced in Version 1.0 @@ -755,7 +825,9 @@ RowSelected DeviceAdded ``` -**Detection:** Code Analyzer check `naming.event.casing` (R2025a) +**Detection:** +- MLCA: Code Analyzer check `naming.event.casing` (R2025a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkEventCasing` **History:** Introduced in Version 1.0 @@ -781,7 +853,9 @@ clustering astrometry.catalogue ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.casing.checkPackageCasing` **History:** Introduced in Version 1.0 @@ -838,7 +912,9 @@ fs = 1000; t = 0:1/fs:1; f = 9; for k = 1:N; dStp(k) = (1/2)*Stp(k-2) + (-2/3)*Stp(k-1); end ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkOneStatementPerLine` **History:** Introduced in Version 1.0 @@ -874,7 +950,9 @@ molarVolume = 8.314*temperature/pressure; record = queryEmployees("ABF4578"); ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkMagicNumber` **History:** Introduced in Version 1.0 @@ -903,7 +981,10 @@ x = 1.0e-1; x = .1; ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkZeroBeforeDecimalPoint` + **History:** Introduced in Version 1.0 @@ -947,7 +1028,9 @@ h = 0.5*gravity*t.^2; end ``` -**Detection:** Not detected as a guideline. Is detected as a Code Analyzer warning by check `GVMIS` (R2021b) +**Detection:** +- MLCA: Not detected as a guideline. Is detected as a Code Analyzer warning by check `GVMIS` (R2021b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkGlobalUsed` **History:** Introduced in Version 1.0 @@ -990,7 +1073,9 @@ end end ``` -**Detection:** Optionally by enabling Code Analyzer check `DAFPV` (R2023a) +**Detection:** +- MLCA: Optionally by enabling Code Analyzer check `DAFPV` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkPersistentUsed` **History:** Introduced in Version 1.0 @@ -1019,7 +1104,9 @@ Experiment.Range = [200 400]; Experiment.Harmonic = true; ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkContiguousStructFieldDefinitions` **History:** Introduced in Version 1.0 @@ -1051,7 +1138,9 @@ missions = ["Mercury" "Gemini" "Apollo"]; missions = {'Mercury' 'Gemini' 'Apollo'}; ``` -**Detection:** Optionally by enabling Code Analyzer check `DAFCVC` (R2024a) +**Detection:** +- MLCA: Optionally by enabling Code Analyzer check `DAFCVC` (R2024a) +- CC4M: `monkeyproof.cc4m_checks.standardReports.reportCellArrays`- Report, known datatypes of cell content reported, but no violations highlighted. **History:** Introduced in Version 1.0 @@ -1083,7 +1172,9 @@ load catalogue.mat % command form clear all % command form ``` -**Detection:** Optionally by enabling Code Analyzer check `DAFCF` (R2023a) +**Detection:** +- MLCA: Optionally by enabling Code Analyzer check `DAFCF` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkCommandSyntax` **History:** Introduced in Version 1.0 @@ -1115,7 +1206,9 @@ y = -2^2; % Is this 4 or -4? m = A > 2 && B < 10 || C == 2; ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkParenthesesMathematicalOperators` and `monkeyproof.cc4m_checks.standardChecks.checkParenthesesLogicalOperators` **History:** Introduced in Version 1.0 @@ -1144,7 +1237,9 @@ areEqual = isapprox(a, b); % introduced in R2024b areEqual = (a == b); ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkComparisons` **History:** Introduced in Version 1.0 @@ -1245,7 +1340,9 @@ for m = 1:size(A,1) end ``` -**Detection:** Code Analyzer check `MNCSN` (R2023a) +**Detection:** +- MLCA: Code Analyzer check `MNCSN` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNestingDepth` **History:** Introduced in Version 1.0 @@ -1277,7 +1374,9 @@ for k = 1:5 end ``` -**Detection:** Not detectable as a guideline. Is detected as a Code Analyzer warning by check `AGROW` (R2006b) +**Detection:** +- MLCA: Not detectable as a guideline. Is detected as a Code Analyzer warning by check `AGROW` (R2006b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -1308,7 +1407,9 @@ for ii = 1:n end ``` -**Detection:** Code Analyzer check `FXSET` (R2007b) +**Detection:** +- MLCA: Code Analyzer check `FXSET` (R2007b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -1349,7 +1450,9 @@ for ii = 1:length(data) % Sum positive values end ``` -**Detection:** Optionally by enabling Code Analyzer checks `DAFCO` (continue), `DAFBR` (break), and `DAFRT` (return) +**Detection:** +- MLCA: Optionally by enabling Code Analyzer checks `DAFCO` (continue), `DAFBR` (break), and `DAFRT` (return) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidFunctions` **History:** Introduced in Version 1.0 @@ -1404,7 +1507,9 @@ switch state end ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSwitchOtherwise` **History:** Introduced in Version 1.0 @@ -1436,7 +1541,9 @@ x = 2*pi; currentFolder = pwd; ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNoInputArg` **History:** Introduced in Version 1.0 @@ -1458,7 +1565,9 @@ currentFolder = pwd; [~, ~, V] = svd(A); ``` -**Detection:** Not detected as a guideline. Is detected as a Code Analyzer warning by check `ASGLU` (R2010b) +**Detection:** +- MLCANot detected as a guideline. Is detected as a Code Analyzer warning by check `ASGLU` (R2010b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -1525,7 +1634,9 @@ for ii = 1:numArrays end ``` -**Detection:** Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +**Detection:** +- MLCA: Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidFunctions` **History:** Introduced in Version 1.0 @@ -1568,7 +1679,9 @@ evalin("base", command); end ``` -**Detection:** Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +**Detection:** +- MLCA: Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidFunctions` **History:** Introduced in Version 1.0 @@ -1600,7 +1713,9 @@ addpath(genpath(newFolder)); end ``` -**Detection:** Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +**Detection:** +- MLCA: Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidFunctions` **History:** Introduced in Version 1.0 @@ -1640,7 +1755,9 @@ for ii = 1:m end ``` -**Detection:** Not currently detected. Applied by default Editor preference setting. +**Detection:** +- MLCA: Not currently detected. Applied by default Editor preference setting. +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkTabCharacterUsed` **History:** Introduced in Version 1.0 @@ -1666,7 +1783,9 @@ for ii = 1:m end ``` -**Detection:** Not currently detected. Applied by default Editor preference setting. +**Detection:** +- MLCA: Not currently detected. Applied by default Editor preference setting. +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkTabCharacterUsed` **History:** Introduced in Version 1.0 @@ -1728,7 +1847,9 @@ B = [1 2 3;4 5 6]; T = rand(5,4,3,"single"); ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkFollowedBySpace` **History:** Introduced in Version 1.0 @@ -1750,7 +1871,9 @@ T = rand(5,4,3,"single"); first = 1;□□ ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkWhiteSpaceEndOfLine` **History:** Introduced in Version 1.0 @@ -1780,7 +1903,9 @@ apparentMagnitude=1.2; plot(x, y, LineWidth = 3); ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` **History:** Introduced in Version 1.0 @@ -1809,7 +1934,9 @@ if (x <= 3) || (x >= 5) A(A>2) ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` **History:** Introduced in Version 1.0 @@ -1837,7 +1964,9 @@ A(A & ~mod(A, 2)) C = A|B ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` **History:** Introduced in Version 1.0 @@ -1869,7 +1998,9 @@ B = A(2 : end – 1); for ii = first + 1:last – 1 ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` (only colon operator itself checked) **History:** Introduced in Version 1.0 @@ -1900,7 +2031,9 @@ A.^2 3 ^ 2 ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` **History:** Introduced in Version 1.0 @@ -1961,7 +2094,9 @@ A = [- 1 1]; y = ~ x; ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSurrBySpaces` **History:** Introduced in Version 1.0 @@ -2229,7 +2364,9 @@ solarAzimuth = acos((term1 - term2)/cos(elevation)); % last element of the current slice is below the lower limit. ``` -**Detection:** Code Analyzer check `LLMNC` (R2023a) +**Detection:** +- MLCA: Code Analyzer check `LLMNC` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkLineLength` **History:** Introduced in Version 1.0 @@ -2256,7 +2393,9 @@ index = (im(:,:,1) > h & (im(:,:,2)+im(:,:,3)) < l) | ... (im(:,:,3) > h & (im(:,:,1)+im(:,:,2)) < l); ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkOperatorsLineContinuation` detects placing of operators relative to the break **History:** Introduced in Version 1.0 @@ -2460,7 +2599,9 @@ end end ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkTabCharacterUsed` **History:** Introduced in Version 1.0 @@ -2480,7 +2621,9 @@ end - Understandability: It is confusing if the function name listed in the file does not match the name used to call that function. -**Detection:** Code Analyzer check `FNDEF` (R14) +**Detection:** +- MLCA: Code Analyzer check `FNDEF` (R14) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -2517,7 +2660,9 @@ function Tk = centigrade2Kelvin(Tc) Tk = Tc + 273.15; ``` -**Detection:** Not currently detected +**Detection:** +- MLCA: Not currently detected +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkFunctionEnd` **History:** Introduced in Version 1.0 @@ -2586,7 +2731,10 @@ Z = P*V/(R*T); % compressibility end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkSubFunction`. Optionally activate `monkeyproof.cc4m_checks.standardChecks.checkComplexity` if "simple" can be tight to the Mcabe complexity of the local function. + **History:** Introduced in Version 1.0 @@ -2628,7 +2776,9 @@ factor = vanDerWaals(temperature, pressure); end ``` -**Detection:** Optionally by enabling Code Analyzer check `DAFNF` +**Detection:** +- MLCA: Optionally by enabling Code Analyzer check `DAFNF` +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNestedFunction` **History:** Introduced in Version 1.0 @@ -2769,7 +2919,9 @@ function dP = dipPotential(xy, Q, D, R, r0, a, b, Dx, Dy, Nxy) function readBonay(T, diam, rh, phi, S, phi, visc, zr, kn) ``` -**Detection:** Code Analyzer check `FCNIL` (R2023a) +**Detection:** +- MLCA: Code Analyzer check `FCNIL` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNumberOfInputsOutputsFunction` **History:** Introduced in Version 1.0 @@ -2796,7 +2948,9 @@ arguments end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkArgumentsBlockUsed` **History:** Introduced in Version 1.0 @@ -2826,7 +2980,9 @@ arguments end ``` -**Detection:** Not detected as a guideline. Use of `varargin` may be detected by enabling Code Analyzer check `DAFVI` (R2023b) +**Detection:** +- MLCA: Not detected as a guideline. Use of `varargin` may be detected by enabling Code Analyzer check `DAFVI` (R2023b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidVararginout` **History:** Introduced in Version 1.0 @@ -2886,7 +3042,9 @@ function [tone, left, right] = psdTone(Pxx, F, rbw, freq) function [msg, nfft, Fs, w, p, flag, rtf] = psdchk(P, x, y) ``` -**Detection:** Code Analyzer check `FCNOL` (R2023a) +**Detection:** +-MLCA: Code Analyzer check `FCNOL` (R2023a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNumberOfInputsOutputsFunction` **History:** Introduced in Version 1.0 @@ -2941,7 +3099,9 @@ end function [tone, left, right] = psdTone(Pxx, F, rbw, freq) ``` -**Detection:** Code Analyzer check `NCOMMA` (R2012b) +**Detection:** +- MLCA: Code Analyzer check `NCOMMA` (R2012b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkMissingComma` **History:** Introduced in Version 1.0 @@ -2961,7 +3121,9 @@ function [tone, left, right] = psdTone(Pxx, F, rbw, freq) - Maintainability: Matching the class name and file name makes it easier to locate the class definition when debugging or modifying code. -**Detection:** Code Analyzer check `MCFIL` (R2008a) +**Detection:** +- MLCA: Code Analyzer check `MCFIL` (R2008a) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -3030,7 +3192,9 @@ classdef OpticFlow end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkDuplicateAttributes` **History:** Introduced in Version 1.0 @@ -3072,7 +3236,9 @@ classdef OpticFlow end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkDuplicateAttributes` **History:** Introduced in Version 1.0 @@ -3283,7 +3449,9 @@ classdef Rectangle end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkDuplicateAttributes` **History:** Introduced in Version 1.0 @@ -3344,7 +3512,9 @@ classdef SquareMatrix end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkNumberOfOutputsConstructor` **History:** Introduced in Version 1.0 @@ -3428,7 +3598,9 @@ classdef Rectangle end ``` -**Detection:** Not detectable +**Detection:** +- MLCA: Not detectable +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkGetterAndSetter`; Also set methods are reported. **History:** Introduced in Version 1.0 @@ -3476,7 +3648,9 @@ See documentation on Modular Indexing for detailed examples - Readability: Fixing Code Analyzer warnings ensures that code is free of potential issues like unused variables, unreachable code, or poor formatting resulting in cleaner and more readable code. -**Detection:** Indicated in Editor or Code Analyzer Report +**Detection:** +- MLCA: Indicated in Editor or Code Analyzer Report +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkEditorWarnings` (reporting MLCA warnings) **History:** Introduced in Version 1.0 @@ -3592,7 +3766,9 @@ end end ``` -**Detection:** Optionally by enabling Code Analyzer check `CTCH` (R2010b) +**Detection:** +- MLCA: Optionally by enabling Code Analyzer check `CTCH` (R2010b) +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkTryExceptionHandling` **History:** Introduced in Version 1.0 @@ -3665,7 +3841,9 @@ GitHub API request failed: Could not access server. https://api.github.com/search/repositories?q=language:matlab. ``` -**Detection:** Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d). +**Detection:** +- MLCA: Optionally using [custom Code Analyzer check for existing functions](https://www.mathworks.com/help/matlab/matlab_env/configure-code-analyzer.html#mw_38519ef1-c176-4933-b2e6-bd17e641681d). +- CC4M: `monkeyproof.cc4m_checks.standardChecks.checkAvoidFunctions` **History:** Introduced in Version 1.0 From 7dcba8110d2be3aa2fe61c450e0d449aafcf4b94 Mon Sep 17 00:00:00 2001 From: "co.melissant" Date: Tue, 14 Oct 2025 09:44:01 +0200 Subject: [PATCH 3/4] # update ToC --- MATLAB-Coding-Guidelines.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MATLAB-Coding-Guidelines.md b/MATLAB-Coding-Guidelines.md index 3e2f319..fd43f94 100644 --- a/MATLAB-Coding-Guidelines.md +++ b/MATLAB-Coding-Guidelines.md @@ -2,6 +2,8 @@ ## Table of Contents +- [Why this fork: use of CC4M](#why-this-fork-use-of-cc4m) + - [Detection using CC4M](#detection-using-cc4m) - [Motivations for the Guidelines](#motivations-for-the-guidelines) - [Understanding the Coding Guidelines](#understanding-the-coding-guidelines) - [How Guidelines are Documented](#how-guidelines-are-documented) From 77dfd4faca4f5d941aad071c7edb0d3e38551c87 Mon Sep 17 00:00:00 2001 From: "co.melissant" Date: Tue, 14 Oct 2025 10:26:03 +0200 Subject: [PATCH 4/4] # review --- MATLAB-Coding-Guidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MATLAB-Coding-Guidelines.md b/MATLAB-Coding-Guidelines.md index fd43f94..a013015 100644 --- a/MATLAB-Coding-Guidelines.md +++ b/MATLAB-Coding-Guidelines.md @@ -54,7 +54,7 @@ All guidelines of type "Rule" are assigned priority "Highly recommended" and all Why use CC4M for checking compliance with the MATLAB Guidelines? - Using CC4M for detecting violations comes with a coverage of over 60% of all guidelines (compared to ~30% by using the MATLAB Code Analyzer) - CC4M runs all checks in MATLAB R2017b and newer with the note that new features (like `arguments` block) are only checked for in the releases were the feature is available. -- The Violations report includes a link to the violated guideline, making the checking process a learning experiecne as well. +- The violations report includes a link to the violated guideline, making the checking process a learning experience as well. - Other valuable features and all available checks are described in the [documentation](https://doc.monkeyproofsolutions.nl/code-checker-for-matlab/code-checker-for-matlab/index.html). ## Deviations from original @@ -64,7 +64,7 @@ Why use CC4M for checking compliance with the MATLAB Guidelines? - The "Detection" section of every guideline is expanded in case CC4M can detect violations.