Skip to content

Whitespace check-in #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2022
Merged

Whitespace check-in #720

merged 1 commit into from
Jul 27, 2022

Conversation

noloader
Copy link
Contributor

This commit removes extraneous trailing whitespace from text-based files.

The script used to clean the files is shown below. It is also available as a ZIP in case you want to add it to the distribution files: whitespace.sh.zip.

#!/usr/bin/env bash

if ! command -v unix2dos &>/dev/null; then
    echo "Please install unix2dos to fix end-of-line conversions"
    exit 1
fi

# Directory to process
ESAPI_DIR="${PWD}"

# sed options for Unix, Linux and MacOS
if [[ $(uname -s | grep -i 'darwin') ]] ; then
    SED_OPTS="-i ''"
else
    SED_OPTS="-i"
fi

# Clean trailing whitespace in java files
IFS= find "${ESAPI_DIR}" -type f -name '*.java' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    
done

# Clean trailing whitespace in text files
IFS= find "${ESAPI_DIR}" -type f -name '*.txt' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    unix2dos "${file}" &>/dev/null
    
done

# Clean trailing whitespace in markdown files
IFS= find "${ESAPI_DIR}" -type f -name '*.md' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    
done

# Clean trailing whitespace in html files
IFS= find "${ESAPI_DIR}" -type f -name '*.html' -print | while read -r file
do

    sed "${SED_OPTS}" -e's/[[:space:]]*$//' "${file}"
    # unix2dos "${file}" &>/dev/null
    
done

exit 0

@kwwall
Copy link
Contributor

kwwall commented Jul 16, 2022

@noloader - It's pretty much only the release notes and I think the CONTRIBUTING-TO-ESAPI.txt files that we leave in DOS format, because of all the Windows uses who still use 'notepad' (and not even 'notepad++') to read them. Sigh. But most of the other text files that I create are UNIX format.

Also, we don't have any files with whitespace in the name, so there's no need for the IFS= trick in the loops. What do you think we are? A bunch of cavemen? I'd personally reject any PR that had a file name with whitespace in the name.

@kwwall
Copy link
Contributor

kwwall commented Jul 16, 2022

Also, trailing whitespace doesn't bother me that much. There are 'diff' options to ignore that. :)

@noloader
Copy link
Contributor Author

noloader commented Jul 16, 2022

Thanks @kwwall,

The problem I am running into is, files I touch have them. So when I clean up the files I touch it includes a bunch of changes not relevant to my work. My hope is to clear all the extraneous whitespace as a base line. Then, when I cleanup the files I touch there are no extra changes.

so there's no need for the IFS= trick in the loops

Yeah, the code I used was copy/paste from my Build Scripts. It handles whitespace in filenames properly, so it should never do any harm.

@kwwall
Copy link
Contributor

kwwall commented Jul 16, 2022 via email

@kwwall
Copy link
Contributor

kwwall commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants