Skip to content

Commit

Permalink
vlajos#43 Whitelist handling tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vlajos committed Aug 9, 2020
1 parent e3b14de commit 4293ac2
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ File filtering options:

Whitelisting files/entries:

Misspell-fixer automatically ignores the issues matching to the patterns listed in `.misspell-fixer.ignore`.
Misspell-fixer automatically ignores the issues matching to the patterns listed in `.misspell-fixer.ignore` or `.github/.misspell-fixer.ignore`.
The format of this file follows the prefiltering's temporary result format:

`^filename:line number:matched word`

* `-W` can be used to append the found issues instead of fixing them based on the other settings.
* `-w filename` can be used to override the ignore file's name.

The ignore file is interpreted as a `grep` exclusion list.
It is applied after the prefiltering step as a set of grep expression.
Expand Down
2 changes: 2 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ misspell-fixer (0.4-1) unstable; urgency=medium
* Update debian Standards version
* Doc updates
* Make tests timezone sign independent
* -w option to override whitelist file
* Use .github/.misspell-fixer.ignore automatically if it exist

-- Veres Lajos <[email protected]> Tue, 24 Mar 2020 21:47:20 +0000

Expand Down
4 changes: 3 additions & 1 deletion doc/misspell-fixer.1
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ File filtering options:
.P
Whitelisting files/entries:
.P
Misspell\-fixer automatically ignores the issues matching to the patterns listed in \fB\.misspell\-fixer\.ignore\fR\. The format of this file follows the prefiltering\'s temporary result format:
Misspell\-fixer automatically ignores the issues matching to the patterns listed in \fB\.misspell\-fixer\.ignore\fR or \fB\.github/\.misspell\-fixer\.ignore\fR\. The format of this file follows the prefiltering\'s temporary result format:
.P
\fB^filename:line number:matched word\fR
.IP "\[ci]" 4
\fB\-W\fR can be used to append the found issues instead of fixing them based on the other settings\.
.IP "\[ci]" 4
\fB\-w filename\fR can be used to override the ignore file\'s name\.
.IP "" 0
.P
The ignore file is interpreted as a \fBgrep\fR exclusion list\. It is applied after the prefiltering step as a set of grep expression\. So it is possible to exclude any prefixes or more specifically whole files with keeping only their file names:
Expand Down
22 changes: 20 additions & 2 deletions lib/initialisation_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function initialise_variables {
export bash_arg

export opt_whitelist_save=0

export opt_whitelist_filename=".misspell-fixer.ignore"

rules_safe0="${rules_directory}/safe.0.sed"
Expand Down Expand Up @@ -85,7 +86,7 @@ function initialise_variables {

function process_command_arguments {
local OPTIND
while getopts ":dvorfsibnRVDGmughWN:P:" opt; do
while getopts ":dvorfsibnRVDGmughWN:P:w:" opt; do
case $opt in
d)
warning "-d Enable debug mode."
Expand Down Expand Up @@ -180,8 +181,13 @@ function process_command_arguments {
fi
return 10
;;
w)
warning "-w Use $OPTARG as white list file instead of "\
"$opt_whitelist_filename."
opt_whitelist_filename=$OPTARG
;;
W)
warning "-W Save found misspelled file entries into"\
warning "-W Save found misspelled file entries into "\
"$opt_whitelist_filename instead of fixing them."
opt_whitelist_save=1
;;
Expand Down Expand Up @@ -248,6 +254,18 @@ function handle_parameter_conflicts {
return 0
}

function handle_whitelist_configfile {
if [[ -s ".github/$opt_whitelist_filename" && -s "$opt_whitelist_filename" ]]; then
warning "We found both .github/$opt_whitelist_filename and $opt_whitelist_filename."\
" We can handle only one at the moment."
return 105
fi

if [[ -s ".github/$opt_whitelist_filename" ]]; then
opt_whitelist_filename=".github/$opt_whitelist_filename"
fi
}

function check_grep_version {
local current_version
current_version=$($GREP --version|head -1|sed -e 's/.* //g')
Expand Down
6 changes: 6 additions & 0 deletions misspell-fixer
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ then
retval=$?
fi

if [[ $retval == 0 ]]
then
handle_whitelist_configfile
retval=$?
fi

if [[ $retval == 0 ]]
then
if [[ $opt_debug = 1 ]]
Expand Down
3 changes: 3 additions & 0 deletions test/expected.whitelist_vs_double_configs.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
misspell-fixer: -r Enable real run. Overwrite original files!
misspell-fixer: Target directories: work
misspell-fixer: We found both .github/.misspell-fixer.ignore and .misspell-fixer.ignore. We can handle only one at the moment.
33 changes: 33 additions & 0 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,43 @@ testWhitelist(){
cd -
}

testWhitelistWithFileNameOverride(){
cp test/stubs/0.txt $TEMP/work/0.txt
cp test/stubs/0.txt $TEMP/expected/0.txt
local whitelist=".misspell-fixer.ignore.override"
cd $TEMP
assertFalse 'Whitelist should not exist' "[ -s $whitelist ]"
$RUN "-Ww$whitelist" work
assertTrue 'Whitelist should exist' "[ -s $whitelist ]"
cd -
cp test/stubs/0.txt $TEMP/work/1.txt
cp test/expecteds/0.txt $TEMP/expected/1.txt
runAndCompare "-rnw$whitelist"
cd $TEMP
rm $whitelist
cd -
}

testWhitelistConflictWithDoubleWhitelist(){
echo x > $TEMP/.misspell-fixer.ignore
mkdir $TEMP/.github
echo x > $TEMP/.github/.misspell-fixer.ignore
runAndCompareOutput -r whitelist_vs_double_configs

cd $TEMP
$RUN -r .
assertSame 105 $?
cd -

rm -rf $TEMP/.github $TEMP/.misspell-fixer.ignore
}

suite(){
export TEST_OUTPUT=$TEMP/output.default
suite_addTest testWhitelist
suite_addTest testWhitelistWithFileNameOverride
suite_addTest testWhitelistConflictWithRealRun
suite_addTest testWhitelistConflictWithDoubleWhitelist
suite_addTest testShowDiff
suite_addTest testErrors
suite_addTest testOnlyDir
Expand Down

0 comments on commit 4293ac2

Please sign in to comment.