-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check trailing whitespace on CI (#1498)
- Loading branch information
1 parent
559a478
commit f882bb0
Showing
23 changed files
with
250 additions
and
188 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { EOL } from 'node:os'; | ||
import fs from 'node:fs'; | ||
|
||
const filesWithTrailingWhitespace: Record<string, number[]> = {}; | ||
|
||
const files = | ||
fs | ||
.readFileSync(0, 'utf8') | ||
.split(EOL) | ||
.filter((f) => f.length > 0); | ||
|
||
console.log(`Check ${files.length} files for trailing whitespace`); | ||
|
||
files.forEach((filename) => { | ||
const contents = fs.readFileSync(filename, 'utf8'); | ||
const lines = contents.split(EOL); | ||
|
||
lines.forEach((line, index) => { | ||
if (line.endsWith(' ')) { | ||
if (!(filename in filesWithTrailingWhitespace)) { | ||
filesWithTrailingWhitespace[filename] = []; | ||
} | ||
|
||
filesWithTrailingWhitespace[filename].push(index + 1); | ||
} | ||
}); | ||
}); | ||
|
||
const fileNamesWithTrailingWhitespace = Object.keys(filesWithTrailingWhitespace); | ||
const fileCount = fileNamesWithTrailingWhitespace.length; | ||
|
||
if (fileCount === 0) { | ||
console.log('No files with trailing whitespace'); | ||
process.exit(0); | ||
} | ||
|
||
const errorMessage = | ||
fileNamesWithTrailingWhitespace | ||
.map((filename) => { | ||
const specification = | ||
filesWithTrailingWhitespace[filename] | ||
.map((lineNumber) => ` ${filename}:${lineNumber}`) | ||
.join(EOL); | ||
|
||
return ` ${filename}:${EOL}${specification}`; | ||
}) | ||
.join(EOL); | ||
|
||
console.error(`Found ${fileCount} files with trailing whitespace:${EOL}${errorMessage}`); | ||
process.exit(1); |
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
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
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
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
Oops, something went wrong.