mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #2862 from rivy/fix.whitespace
refactor/polish ~ whitespace fixup
This commit is contained in:
commit
6723a54610
8 changed files with 32 additions and 30 deletions
16
GNUmakefile
16
GNUmakefile
|
@ -47,12 +47,12 @@ BUSYBOX_VER := 1.32.1
|
|||
BUSYBOX_SRC := $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)
|
||||
|
||||
ifeq ($(SELINUX_ENABLED),)
|
||||
SELINUX_ENABLED := 0
|
||||
ifneq ($(OS),Windows_NT)
|
||||
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
|
||||
SELINUX_ENABLED := 1
|
||||
endif
|
||||
endif
|
||||
SELINUX_ENABLED := 0
|
||||
ifneq ($(OS),Windows_NT)
|
||||
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
|
||||
SELINUX_ENABLED := 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# Possible programs
|
||||
|
@ -161,11 +161,11 @@ SELINUX_PROGS := \
|
|||
runcon
|
||||
|
||||
ifneq ($(OS),Windows_NT)
|
||||
PROGS := $(PROGS) $(UNIX_PROGS)
|
||||
PROGS := $(PROGS) $(UNIX_PROGS)
|
||||
endif
|
||||
|
||||
ifeq ($(SELINUX_ENABLED),1)
|
||||
PROGS := $(PROGS) $(SELINUX_PROGS)
|
||||
PROGS := $(PROGS) $(SELINUX_PROGS)
|
||||
endif
|
||||
|
||||
UTILS ?= $(PROGS)
|
||||
|
|
|
@ -20,7 +20,7 @@ and most other parts of the world.
|
|||
This particular file has about 170,000 lines, each of which is no longer
|
||||
than 96 characters:
|
||||
|
||||
$ wc -lL shakespeare.txt
|
||||
$ wc -lL shakespeare.txt
|
||||
170592 96 shakespeare.txt
|
||||
|
||||
You could use files of different shapes and sizes to test the
|
||||
|
|
|
@ -29,4 +29,4 @@ name = "nl"
|
|||
path = "src/main.rs"
|
||||
|
||||
[package.metadata.cargo-udeps.ignore]
|
||||
normal = ["uucore_procs"]
|
||||
normal = ["uucore_procs"]
|
||||
|
|
|
@ -24,4 +24,4 @@ name = "numfmt"
|
|||
path = "src/main.rs"
|
||||
|
||||
[package.metadata.cargo-udeps.ignore]
|
||||
normal = ["uucore_procs"]
|
||||
normal = ["uucore_procs"]
|
||||
|
|
|
@ -217,7 +217,7 @@ pub fn uu_app() -> App<'static, 'static> {
|
|||
// This is solely for testing.
|
||||
// Do not document.
|
||||
// It is relatively difficult to ensure that there is a tty on stdin.
|
||||
// Since rm acts differently depending on that, without this option,
|
||||
// Since rm acts differently depending on that, without this option,
|
||||
// it'd be harder to test the parts of rm that depend on that setting.
|
||||
.arg(
|
||||
Arg::with_name(PRESUME_INPUT_TTY)
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
//! .get_matches_from(vec![
|
||||
//! "app", "--backup=t", "--suffix=bak~"
|
||||
//! ]);
|
||||
//!
|
||||
//!
|
||||
//! let backup_mode = match backup_control::determine_backup_mode(&matches) {
|
||||
//! Err(e) => {
|
||||
//! show!(e);
|
||||
|
@ -321,7 +321,7 @@ pub fn determine_backup_suffix(matches: &ArgMatches) -> String {
|
|||
/// .get_matches_from(vec![
|
||||
/// "app", "-b", "--backup=n"
|
||||
/// ]);
|
||||
///
|
||||
///
|
||||
/// let backup_mode = backup_control::determine_backup_mode(&matches);
|
||||
///
|
||||
/// assert!(backup_mode.is_err());
|
||||
|
|
|
@ -340,10 +340,10 @@ fn test_dictionary_order() {
|
|||
fn test_dictionary_order2() {
|
||||
for non_dictionary_order2_param in &["-d"] {
|
||||
new_ucmd!()
|
||||
.pipe_in("a👦🏻aa b\naaaa b") // spell-checker:disable-line
|
||||
.pipe_in("a👦🏻aa\tb\naaaa\tb") // spell-checker:disable-line
|
||||
.arg(non_dictionary_order2_param) // spell-checker:disable-line
|
||||
.succeeds()
|
||||
.stdout_only("a👦🏻aa b\naaaa b\n"); // spell-checker:disable-line
|
||||
.stdout_only("a👦🏻aa\tb\naaaa\tb\n"); // spell-checker:disable-line
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
@setLocal
|
||||
@echo off
|
||||
|
||||
:: `test-repo-whitespace [DIR]...`
|
||||
:: `test-repo-whitespace [DIR]...` v2022.01.01
|
||||
:: style inspector ~ whitespace: find nonconforming files in repository
|
||||
|
||||
:: Copyright (C) 2016-2020 ~ Roy Ivy III <rivy.dev@gmail.com>
|
||||
:: Copyright (C) 2016-2022 ~ Roy Ivy III <rivy.dev@gmail.com>
|
||||
:: License: MIT/Apache-2.0 (see https://opensource.org/licenses/Apache-2.0 , https://opensource.org/licenses/MIT)
|
||||
:: * this software is provided for free, WITHOUT ANY EXPRESS OR IMPLIED WARRANTY (see the license for details)
|
||||
|
||||
:: spell-checker:ignore (ignore) CTYPE POSIX RETval RETvar akefile makefile makefiles multiline
|
||||
:: spell-checker:ignore (shell/cmd) COMSPEC ERRORLEVEL
|
||||
:: spell-checker:ignore () CTYPE POSIX Tval Tvar akefile makefile makefiles multiline testdata
|
||||
|
||||
:config
|
||||
set "_exclude_dir=(?i)[_.#]build|[.]git|[.]gpg|[.]vs|fixtures|vendor"
|
||||
set "_exclude=(?i)[.](cache|dll|exe|gif|gz|zip)$"
|
||||
set "_exclude_dirs_rx=(?i)[_.#]build|[.]git|[.]gpg|[.]obj|[.]vs|fixtures|node_modules|target|testdata|test-resources|vendor"
|
||||
set "_exclude_files_rx=(?i)[.](cache|dll|exe|gif|gz|ico|png|zip)$"
|
||||
set "_crlf_files_rx=(?i)[.](bat|cmd|csv)$"
|
||||
set "_tabbed_files_rx=(?i)^^(.*[.]go|go[.](mod|sum)|(GNU)?[Mm]akefile([.].*)?)$"
|
||||
:config_done
|
||||
|
||||
set _dp0=%~dp0.
|
||||
|
@ -34,36 +36,36 @@ if /i "%LC_CTYPE%"=="posix" (set "LC_CTYPE=C") &:: `pcregrep` doesn't understand
|
|||
set "ERRORLEVEL="
|
||||
set "ERROR="
|
||||
:: 1. Test for TABs within leading whitespace (except go files makefiles)
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --exclude "(?i)[.]go$" --exclude "go[.](mod|sum)" --exclude "(GNU)?[Mm]akefile([.].*)?" --count --files-with-matches --recursive "^\s*\t" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --exclude "%_tabbed_files_rx%" --count --files-with-matches --recursive "^\s*\t" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with TABs within leading whitespace [file:#lines_matched])
|
||||
|
||||
:: 2. Test for lines with internal TABs
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --count --files-with-matches --recursive "^.*[^\t]\t" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --count --files-with-matches --recursive "^.*[^\t]\t" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with lines containing internal TABs [file:#lines_matched])
|
||||
|
||||
:: 3. Test that makefiles have ONLY initial-TAB leading whitespace
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --include "(GNU)?[Mm]akefile([.].*)?" --exclude "[.](to|y)ml$" --recursive --line-number --invert-match "^([\t]\s*\S|\S|$)" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --include "(GNU)?[Mm]akefile([.].*)?" --exclude "[.](to|y)ml$" --recursive --line-number --invert-match "^([\t]\s*\S|\S|$)" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: Makefiles found with lines having non-TAB leading whitespace [file:line_number])
|
||||
|
||||
:: 4. Test for non-LF line endings
|
||||
set "HAVE_NonLF_ERROR="
|
||||
"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" -NLF --files-with-matches --multiline --recursive "\r[^\n]" %dirs%
|
||||
"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" -NLF --files-with-matches --multiline --recursive "\r[^\n]" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set HAVE_NonLF_ERROR=1 & echo ## files found with CR line endings)
|
||||
"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --exclude "(?i)\.bat$|\.cmd$" -NLF --files-with-matches --multiline --recursive "\r\n" %dirs%
|
||||
"%PCREGREP%" --buffer-size=1M -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --exclude "%_crlf_files_rx%" -NLF --files-with-matches --multiline --recursive "\r\n" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set HAVE_NonLF_ERROR=1 & echo ## files found with CRLF line endings)
|
||||
if DEFINED HAVE_NonLF_ERROR ( set ERROR=1 & echo ERROR: files found with non-LF line endings)
|
||||
|
||||
:: 5. Test for files without trailing newline
|
||||
:: "%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-without-match --multiline --recursive "\r?[\r\n]\z" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-with-matches --multiline --recursive "\z" %dirs%
|
||||
:: "%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --files-without-match --multiline --recursive "\r?[\r\n]\z" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --files-with-matches --multiline --recursive "\z" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found without trailing newline)
|
||||
|
||||
:: 6. Test for files with lines having trailing whitespace
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --recursive --line-number "\s$" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --recursive --line-number "\s$" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with lines having trailing whitespace [file:line_number])
|
||||
|
||||
:: 7. Test for files with BOM
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dir%" --exclude "%_exclude%" --files-with-matches --multiline --recursive "\A[\xEF][\xBB][\xBF]" %dirs%
|
||||
"%PCREGREP%" -I --exclude-dir "%_exclude_dirs_rx%" --exclude "%_exclude_files_rx%" --files-with-matches --multiline --recursive "\A[\xEF][\xBB][\xBF]" %dirs%
|
||||
if NOT "%ERRORLEVEL%" == "1" ( set ERROR=1 & echo ERROR: files found with leading BOM)
|
||||
|
||||
:script_done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue