Skip to content

Commit 01643c7

Browse files
Merge pull request #2415 from coreinfrastructure/tweak_claude
Use ',' as the temporary file prefix. Signed-off-by: David A. Wheeler <[email protected]>
2 parents a740200 + 741edc0 commit 01643c7

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

,whitespace.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This line has trailing spaces
2+
And this one too

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
# The "application.js" file only contains comments, and the
99
# ESLint parser has trouble with comment-only files, so skip it:
1010
**/application.js
11+
# Ignore temporary files beginning with comma:
12+
,*

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ AllCops:
5656
- 'railroader/**/*'
5757
- '.pryrc'
5858
- 'license_okay'
59+
- ',*'
5960

6061
# This will ALWAYS be disabled. We *want* to be able disable cops.
6162
Style/DisableCopsWithinSourceCodeDirective:

CLAUDE.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This is the **OpenSSF Best Practices Badge** project (formerly CII Best Practice
2525
### Code Quality & Linting
2626

2727
- `rake` or `rake default` - Run complete CI pipeline (linting, tests, security checks).
28-
- `rake rubocop` - Ruby style checker
28+
- `rake rubocop` - Ruby style checker
2929
- `rake rails_best_practices` - Rails-specific best practices source checker
3030
- `rake markdownlint` - Markdown linting
3131
- `rake eslint` - JavaScript linting
@@ -83,7 +83,7 @@ not done on the local system.
8383
Security is *extremely* important to this project. Some features:
8484

8585
- **Encrypted Data**: User emails encrypted with AES-256-GCM
86-
- **Blind Indexing**: Email searches use blind indices for privacy
86+
- **Blind Indexing**: Email searches use blind indices for privacy
8787
- **CSRF Protection**: All forms protected with Rails CSRF tokens
8888
- **Rate Limiting**: Uses `rack-attack` for DoS protection
8989
- **Content Security Policy**: Strict CSP headers via `secure_headers` gem
@@ -121,7 +121,7 @@ The file `docs/assurance-case.md` explains why we *believe* this is secure.
121121

122122
## Key Configuration Files
123123

124-
- `config/application.rb` - Core Rails app configuration
124+
- `config/application.rb` - Core Rails app configuration
125125
- `config/routes.rb` - Complex routing with locale support
126126
- `lib/tasks/default.rake` - Custom rake tasks including full CI pipeline
127127

@@ -169,7 +169,7 @@ Security is *VERY* important in this application.
169169
Key environment variables for development:
170170

171171
- `RAILS_ENV` - Rails environment (development/test/production)
172-
- `EMAIL_ENCRYPTION_KEY` - 64 hex digits for email encryption
172+
- `EMAIL_ENCRYPTION_KEY` - 64 hex digits for email encryption
173173
- `EMAIL_BLIND_INDEX_KEY` - 64 hex digits for email search indices
174174
- `BADGEAPP_REAL_PRODUCTION` - Set to "true" only on true production site
175175
- `PUBLIC_HOSTNAME` - Hostname for the application
@@ -192,7 +192,7 @@ Key environment variables for development:
192192
### Security Considerations
193193

194194
- Badge image URLs must be canonical for CDN caching
195-
- All user input requires validation and sanitization
195+
- All user input requires validation and sanitization
196196
- Session timeouts are enforced - don't extend arbitrarily
197197
- Rate limiting is aggressive - be aware when testing
198198

@@ -204,3 +204,11 @@ Key environment variables for development:
204204
- `docs/` - Extensive documentation including security assurance case
205205
- `lib/tasks/default.rake` - CI pipeline and custom tasks
206206
- `test/` - Comprehensive test suite
207+
208+
## Miscellaneous
209+
210+
IMPORTANT: Never have trailing whitespace in text-like files including
211+
source code and markdown files.
212+
213+
IMPORTANT: When creating temporary files, always prefix their names with
214+
a comma to distinguish them.

config/rails_best_practices.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
features: true
77
spec: true
88
without_color: true
9-
exclude: ["railroader/"]
9+
exclude: ["railroader/", "^,.*"]
1010

1111
AddModelVirtualAttributeCheck: { }
1212
AlwaysAddDbIndexCheck: { }

dockerfiles/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ installed on your computer (Install instructions are
1414
2. "cd" into that directory and modify the Dockerfile
1515
to point to the correct base image.
1616
3. Log in to DockerHub
17+
1718
~~~~sh
1819
docker login -u <username>
1920
~~~~
21+
2022
4. Build the docker image (replace `<tag>` below with for example
2123
`2.5.1-stretch`.
24+
2225
~~~~sh
2326
docker build -t <username>/cii-bestpractices:<tag> .
2427
~~~~
28+
2529
5. Push your image.
30+
2631
~~~~sh
2732
docker push <username>/cii-bestpractices:<tag>
2833
~~~~

lib/tasks/default.rake

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# minimize what we install in production, and we try to make our
1818
# CI system similar to production.
1919

20+
require 'English'
2021
require 'json'
2122

2223
# NOTE: Our default runs test:all, not just test.
@@ -191,7 +192,8 @@ end
191192
desc 'Run markdownlint (mdl) - check for markdown problems on **.md files'
192193
task :markdownlint do
193194
# The default configuration is in .mdlrc + style config/markdown_style.rb
194-
sh 'bundle exec mdl *.md docs/*.md'
195+
# Exclude temporary files beginning with comma
196+
sh 'find . -name "*.md" ! -name ",*" -print0 | xargs -0 bundle exec mdl'
195197
end
196198

197199
# Apply JSCS to look for issues in JavaScript files.
@@ -242,24 +244,45 @@ end
242244
# Don't do whitespace checks on these YAML files:
243245
YAML_WS_EXCEPTIONS ||= ':!test/vcr_cassettes/*.yml'
244246

245-
desc 'Check for trailing whitespace in latest proposed (git) patch.'
247+
desc 'Check for trailing whitespace in all text files.'
246248
task :whitespace_check do
247-
if ENV['CI'] # CircleCI modifies database.yml
248-
sh "git diff --check -- . ':!config/database.yml' #{YAML_WS_EXCEPTIONS}"
249+
puts 'Checking for trailing whitespace...'
250+
251+
# Find all files, exclude directories we don't want, exclude comma-prefixed
252+
# files, use file to identify text files, then check for trailing whitespace
253+
# This won't handle filenames with \n but those shouldn't be in our repo!
254+
cmd = <<~SHELL
255+
find . -type f ! -name ',*' \
256+
! -path './vendor/*' ! -path './node_modules/*' \
257+
! -path './railroader/*' ! -path './tmp/*' ! -path './.git/*' \
258+
! -path './log/*' ! -path './test/vcr_cassettes/*' \
259+
! -path './license_finder_report.html' \
260+
! -path './coverage/index.html' \
261+
-print0 | \
262+
xargs -0 file | \
263+
awk -F': ' '$2 ~ /(text|script)/ && $2 !~ /(executable|binary)/ \
264+
{print $1}' | \
265+
xargs grep -l '[[:space:]]$' 2>/dev/null || true
266+
SHELL
267+
268+
output = `#{cmd}`
269+
270+
if output.empty?
271+
puts 'No trailing whitespace found.'
249272
else
250-
sh "git diff --check -- . #{YAML_WS_EXCEPTIONS}"
273+
puts 'Trailing whitespace found in these files:'
274+
puts output
275+
exit 1
251276
end
252277
end
253278

254279
desc 'Check YAML syntax (except project.yml, which is not straight YAML)'
255280
task :yaml_syntax_check do
256-
require 'English'
257-
258281
# Don't check "project.yml" - it's not a straight YAML file, but instead
259282
# it's processed by ERB (even though the filename doesn't admit it).
260283
puts 'Checking YAML syntax...'
261284

262-
find_cmd = "find . -name '*.yml' ! -name 'projects.yml' " \
285+
find_cmd = "find . -name '*.yml' ! -name 'projects.yml' ! -name ',*' " \
263286
"! -path './railroader/*' ! -path './vendor/*' " \
264287
'-exec bundle exec yaml-lint {} + 2>&1'
265288

0 commit comments

Comments
 (0)