Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/style_checker.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ <h3>Configuration on the command-line</h3>
<section>
<h2>Configuration file syntax reference</h2>
<div>
In general the config files follow a simply sytax:
In general the config files follow a simply syntax:
<pre>key: value</pre> The key is some identifier like
tab_width, and the value is the configuration for that
key. Integers are written directly, and strings are enclosed
Expand Down Expand Up @@ -581,6 +581,8 @@ <h4>Consistent semicolons ("end_of_statements")</h4>
effectively bans commas and requires semicolons + newline at
the end of most statements. The exceptions are things like
'return' or the end of compound statements such as 'if'.
Fixing missing semicolons can be disabled with
"no_fix_missing_semicolon".
</div>

<div>
Expand Down
70 changes: 70 additions & 0 deletions make.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[CmdletBinding()]
param (
[switch]$PreCommitChecks,
[switch]$Copyright,
[switch]$Doc,
[switch]$Test,
[switch]$Lint,
[switch]$Style
)


$AllParams =@($PreCommitChecks, $Copyright, $Doc, $Test, $Lint, $Style)

if ($AllParams -notcontains $true) {
$Doc = $true
$Test = $true
$Lint = $true
$Style = $true
}

if ($Lint) {
$Style = $true
}

if ($PreCommitChecks) {
$Copyright = $true
$Doc = $true
$Test = $true
$Lint = $true
}

$ErrorActionPreference = "Stop"

if ($Copyright) {
python hook_scripts\copyright_year.py
}

if ($Doc) {
Push-Location util
python update_docs.py
python update_versions.py
Pop-Location
}

if ($Test) {
Push-Location tests
python run.py
Pop-Location
}

if ($Style) {
python -m pycodestyle miss_hit_core miss_hit mh_bmc mh_copyright mh_debug_enumerate_simulink_blocks mh_debug_parser mh_diff mh_lint mh_metric mh_sl_unpack mh_style mh_trace
}

if ($Lint) {
python -m pylint --rcfile=pylint3.cfg --reports=no miss_hit_core miss_hit mh_bmc mh_copyright mh_debug_enumerate_simulink_blocks mh_debug_parser mh_diff mh_lint mh_metric mh_sl_unpack mh_style mh_trace
}

if ($Package) {
git clean -xdf
Copy-Item -Path setup_gpl.py -Destination setup.py
New-Item -Path "miss_hit_core/resources/assets" -ItemType Directory
Copy-Item -Path docs/style.css -Destination miss_hit_core/resources
Copy-Item -Path docs/assets/* -Destination miss_hit_core/resources/assets
python setup.py sdist bdist_wheel
Remove-Item -Path "miss_hit_core/resources" -Recurse
Copy-Item -Path setup_agpl.py -Destination setup.py
python setup.py sdist bdist_wheel
Remove-Item -Path setup.py
}
4 changes: 4 additions & 0 deletions miss_hit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class Function_Metric(Code_Metric):
"end_of_statements" : Style_Rule(
"Ensures consistent ending of statements."),

"no_fix_missing_semicolon" : Style_Rule(
"Allows statement to not end in a semicolon if"
" 'end_of_statements' is enabled."),

"builtin_shadow" : Style_Rule(
"Checks that assignments do not overwrite builtin functions such as"
" true, false, or pi."),
Expand Down
11 changes: 6 additions & 5 deletions miss_hit_core/m_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ def match_eos(self, n_ast, semi = "", allow_nothing = False):

else:
assert terminator_tokens[0].kind == "NEWLINE"
self.mh.style_issue(ending_token.location,
"end statement with a semicolon",
"end_of_statements",
True)
ending_token.fix.add_semicolon_after = True
if not self.cfg.active("no_fix_missing_semicolon"):
self.mh.style_issue(ending_token.location,
"end statement with a semicolon",
"end_of_statements",
True)
ending_token.fix.add_semicolon_after = True

if first_newline is None:
fixed = False
Expand Down
23 changes: 23 additions & 0 deletions tests/style/no_fix_missing_semicolon/expected_out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="file:../../../docs/style.css">
<title>MISS_HIT Report</title>
</head>
<body>
<header>MISS_HIT Report</header>
<main>
<div></div>
<h1>Issues identified</h1>
<section>
<h2>test.m</h2>
<div class="message"><a href="matlab:opentoline('test.m')">test.m:</a> style: violates naming scheme for scripts</div>
<div class="message"><a href="matlab:opentoline('test.m', 5, 8)">test.m: line 5:</a> style: end this with a semicolon instead of a comma</div>
<div class="message"><a href="matlab:opentoline('test.m', 5, 8)">test.m: line 5:</a> style: end statement with a newline</div>
<div class="message"><a href="matlab:opentoline('test.m', 8, 8)">test.m: line 8:</a> style: end this with a semicolon instead of a comma</div>
<div class="message"><a href="matlab:opentoline('test.m', 8, 8)">test.m: line 8:</a> style: end statement with a newline</div>
</section>
</main>
</body>
</html>
18 changes: 18 additions & 0 deletions tests/style/no_fix_missing_semicolon/expected_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== PLAIN MODE ===
test.m: style: violates naming scheme for scripts [naming_scripts]
In test.m, line 5
| baz = 4, bar = 5;
| ^ style: end this with a semicolon instead of a comma [fixed] [end_of_statements]
In test.m, line 5
| baz = 4, bar = 5;
| ^ style: end statement with a newline [fixed] [end_of_statements]
In test.m, line 9
| bas = 5, foo = 9
| ^ style: end this with a semicolon instead of a comma [fixed] [end_of_statements]
In test.m, line 9
| bas = 5, foo = 9
| ^ style: end statement with a newline [fixed] [end_of_statements]
MISS_HIT Style Summary: 1 file(s) analysed, 5 style issue(s)

=== HTML MODE ===
MISS_HIT Style Summary: 1 file(s) analysed, 5 style issue(s)
1 change: 1 addition & 0 deletions tests/style/no_fix_missing_semicolon/miss_hit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable_rule: "no_fix_missing_semicolon"
8 changes: 8 additions & 0 deletions tests/style/no_fix_missing_semicolon/test.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
% (c) Copyright 2019 Zenuity AB

% Should end in semicolons
foo = 1;
baz = 4, bar = 5;
% foo and spoon should reamin without a semicolon
spoon
bas = 5, foo = 9
10 changes: 10 additions & 0 deletions tests/style/no_fix_missing_semicolon/test.m_fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
% (c) Copyright 2019 Zenuity AB

% Should end in semicolons
foo = 1;
baz = 4;
bar = 5;
% foo and spoon should reamin without a semicolon
spoon
bas = 5;
foo = 9