-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from worldbank/v1.02
v1.02
- Loading branch information
Showing
9 changed files
with
44 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
- [ ] 3.2 **Update version and date** - In the _version_ branch, update the version number and date in all ado-files and all dates in all help files. See section below for details. | ||
- [ ] 3.3 **Update version globals** - Update the _version_ado_ local in the file _lint.ado_ and the _VERSION_ global in _stata_linter_detect.py_ and _stata_linter_correct.py_. | ||
- [ ] 3.4 **Update version in .pkg and .toc** - This has nothing to do with SSC but should be kept up to date to. This is for when people install directly through GitHub using `net install`. If any new command has been added, remember to add the files for that command to the `.pkg` file. | ||
- [ ] 3.5 **Create a .zip file** - Create a .zip file with all ado-files and help files only. These files are not allowed to be in a sub-folder in this .zip file. No other files should be in this folder. Make a copy of this file in the archive folder of this package. | ||
- [ ] 3.5 **Create a .zip file** - Create a .zip file with the files listed below (ado-files, Python scripts, and help files). If a version update ever includes a new ado-file or Python script necessary to run the linter, include that new file in the .zip too. These files are not allowed to be in a sub-folder in this .zip file. No other files should be in this folder. Make a copy of this file in the archive folder of this package. | ||
- [ ] 4. **Email Prof. Baum** - Email the .zip file created in step 3.5 to **[email protected]**. | ||
- [ ] 4.1 - If any commands are added or deleted, make note of that in the email. | ||
- [ ] 4.2 - If any of the meta info (title, description, keywords, version or author/contact) has changed then include those updates in your email. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ The package contains a command that detects bad Stata coding practices in a do-f | |
The command can also correct some of the issues flagged in a new do-file. | ||
The purpose of the command is to help users improve code clarity, readability, and organization in Stata do-files. | ||
This linter is based on the best practices outlined in The DIME Analytics Coding Guide published as an appendix to the book Development Research in Practice. | ||
See here https://worldbank.github.io/dime-data-handbook/coding.html. For more info about this linter, see https://github.com/worldbank/stata_linter. | ||
See here https://worldbank.github.io/dime-data-handbook/coding.html. For more info about this linter, see https://github.com/worldbank/stata-linter. | ||
|
||
### AUTHOR: | ||
"DIME Analytics, DIME, The World Bank Group", [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*! version 1.1 07dec2022 DIME Analytics [email protected] | ||
*! version 1.02 06apr2023 DIME Analytics [email protected] | ||
|
||
capture program drop lint | ||
program lint | ||
|
@@ -536,7 +536,7 @@ capture program drop _checkversions | |
|
||
* IMPORTANT: Every time we have a package update, update the version number here | ||
* Otherwise we'd be introducing a major bug! | ||
local version_ado 1.1 | ||
local version_ado 1.02 | ||
|
||
* Check versions of .py files | ||
python: from sfi import Macro | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{smcl} | ||
{* 07 Dec 2022}{...} | ||
{* 06 Apr 2023}{...} | ||
{hline} | ||
help for {hi:lint} | ||
{hline} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# version 1.1 07dec2022 DIME Analytics [email protected] | ||
# version 1.02 06apr2023 DIME Analytics [email protected] | ||
# Import packages ============ | ||
import os | ||
import re | ||
|
@@ -8,7 +8,7 @@ | |
# Version Global | ||
## VERY IMPORTANT: Update the version number here every time there's an update | ||
## in the package. Otherwise this will cause a major bug | ||
VERSION = "1.1" | ||
VERSION = "1.02" | ||
|
||
# Function to update comment delimiter ============= | ||
# (detection works only when comment delimiter == 0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# version 1.1 07dec2022 DIME Analytics [email protected] | ||
# version 1.02 06apr2023 DIME Analytics [email protected] | ||
# Import packages ==================== | ||
import os | ||
import re | ||
|
@@ -9,7 +9,7 @@ | |
# Version Global | ||
## VERY IMPORTANT: Update the version number here every time there's an update | ||
## in the package. Otherwise this will cause a major bug | ||
VERSION = "1.1" | ||
VERSION = "1.02" | ||
|
||
# simple run entry point | ||
def run(): | ||
|
@@ -247,11 +247,12 @@ def no_space_before_symbol(line): | |
|
||
line = line.split('///')[0] | ||
groups = line.split('"') | ||
pattern = r"(?:[a-z]|[A-Z]|[0-9]|_|\)|')(?:<|>|=|\+|-|\*|\^)" | ||
|
||
for i, group in enumerate(groups): | ||
|
||
if i % 2 == 0: | ||
if re.search(r"(?:[a-z]|[A-Z]|[0-9]|_|\)|')(?:<|>|=|\+|-|\*|\^)", group): | ||
if re.search(pattern, group): | ||
return True | ||
|
||
return False | ||
|
@@ -260,11 +261,12 @@ def no_space_after_symbol(line): | |
|
||
line = line.split('///')[0] | ||
groups = line.split('"') | ||
pattern = r"(?:(?:<|>|=|\+|-|\*|\^)(?:[a-z]|[A-Z]|_|\(|`|\.|$))|(?:(?:<|>|=|\+|\*|\^)(?:[0-9]))" | ||
|
||
for i, group in enumerate(groups): | ||
|
||
if i % 2 == 0: | ||
if re.search(r"(?:<|>|=|\+|-|\*|\^)(?:[a-z]|[A-Z]|[0-9]|_|\(|`|\.|$)", group): | ||
if re.search(pattern, group): | ||
return True | ||
|
||
return False | ||
|
@@ -413,30 +415,42 @@ def too_long_line( | |
return([style_dictionary, excel_output_list]) | ||
|
||
# "if" condition should be explicit | ||
def detect_implicit_if(line): | ||
|
||
search_if = re.search(r"(?:^|\s)(?:if|else if)\s", line.lstrip()) | ||
|
||
if search_if != None: | ||
|
||
line = line[search_if.span()[0]:] | ||
if ( | ||
(re.search(r"missing\(", line) == None) & | ||
(re.search(r"inrange\(", line) == None) & | ||
(re.search(r"inlist\(", line) == None) & | ||
(re.search(r"=|<|>", line) == None) | ||
): | ||
return True | ||
|
||
return False | ||
|
||
def explicit_if( | ||
line_index, line, input_lines, indent, | ||
suppress, style_dictionary, excel_output_list, | ||
tab_space | ||
): | ||
|
||
# warn if "if" statement is used but the condition is not explicit | ||
search_if = re.search(r"^(if|else if) ", line.lstrip()) | ||
if (search_if != None): | ||
if ( | ||
(re.search(r"missing\(", line[search_if.span()[0]:]) == None) & | ||
(re.search(r"((=|<|>))", line[search_if.span()[0]:]) == None) | ||
): | ||
print_output = ( | ||
'''Always explicitly specify the condition in the if statement. ''' + | ||
'''(For example, declare "if var == 1" instead of "if var".) ''' | ||
if detect_implicit_if(line): | ||
print_output = ( | ||
'''Always explicitly specify the condition in the if statement. ''' + | ||
'''(For example, declare "if var == 1" instead of "if var".) ''' | ||
) | ||
if suppress != "1": | ||
print( | ||
'''(line {:d}): '''.format(line_index + 1) + | ||
print_output | ||
) | ||
if suppress != "1": | ||
print( | ||
'''(line {:d}): '''.format(line_index + 1) + | ||
print_output | ||
) | ||
style_dictionary["explicit_if"] += 1 | ||
excel_output_list.append([line_index + 1, "style", print_output]) | ||
style_dictionary["explicit_if"] += 1 | ||
excel_output_list.append([line_index + 1, "style", print_output]) | ||
|
||
return([style_dictionary, excel_output_list]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# version 1.1 07dec2022 DIME Analytics [email protected] | ||
# version 1.02 06apr2023 DIME Analytics [email protected] | ||
# Import packages ==================== | ||
import re | ||
import pandas as pd | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
v 1.1 | ||
v 1.02 | ||
d DIME Analytics, World Bank Group, Development Economics Research | ||
p stata_linter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters