Skip to content

Commit f19262a

Browse files
authored
Add projectile-cache-file to projectile-globally-ignored-files default (#1966)
- Include projectile-cache-file in projectile-globally-ignored-files default - Add :safe predicate to allow dir-locals configuration - Add tests for default values and :safe predicate validation - Update related file and test matching functions to use let* variants - Improve variable binding consistency and future compatibility
1 parent 613f033 commit f19262a

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
* [#1837](https://github.com/bbatsov/projectile/issues/1837): Add `eat` project terminal commands with keybindings `x x` and `x 4 x`.
88

99
### Changes
10-
11-
* Set `projectile-auto-discover` to `nil` by default (to avoid startup slowdowns in some situations).
10+
* [#1958](https://github.com/bbatsov/projectile/issues/1958): Exclude `.projectile-cache.eld` from search results (ripgrep/ag/grep) by default.
1211
* [#1957](https://github.com/bbatsov/projectile/pull/1957): Add `:caller` information to calls to `ivy-read` (used by packages like `ivy-rich`).
12+
* [#1954](https://github.com/bbatsov/projectile/issues/1954): update ELisp for usage.html / "Removal of missing projects"
1313
* [#1947](https://github.com/bbatsov/projectile/issues/1947): `projectile-project-name` should be marked as safe.
14+
* Set `projectile-auto-discover` to `nil` by default (to avoid startup slowdowns in some situations).
1415
* [#1943](https://github.com/bbatsov/projectile/pull/1943): Consider `projectile-indexing-method` to be safe as a dir-local variable if it is one of the preset values.
1516
* [#1936](https://github.com/bbatsov/projectile/issues/1936): Do not require selecting a project when using `M-x projectile-invalidate-cache`, since there is a global cache that is also cleared by that command, even when not operating on any specific project.
1617

projectile.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,11 @@ Similar to '#' in .gitignore files."
405405
:package-version '(projectile . "2.2.0"))
406406

407407
(defcustom projectile-globally-ignored-files
408-
(list projectile-tags-file-name)
408+
(list projectile-tags-file-name projectile-cache-file)
409409
"A list of files globally ignored by projectile.
410410
Note that files aren't filtered if `projectile-indexing-method'
411411
is set to `alien'."
412+
:safe (lambda (x) (not (remq t (mapcar #'stringp x))))
412413
:group 'projectile
413414
:type '(repeat string))
414415

@@ -2802,7 +2803,7 @@ If KIND is not provided, a list of possible kinds can be chosen."
28022803
:caller 'projectile-read-file))))
28032804
(error "No related files found")))
28042805

2805-
(if-let ((candidates (projectile--related-files file kind)))
2806+
(if-let* ((candidates (projectile--related-files file kind)))
28062807
(projectile-expand-root (projectile--choose-from-candidates candidates :caller 'projectile-read-file))
28072808
(error
28082809
"No matching related file as `%s' found for project type `%s'"
@@ -4237,12 +4238,12 @@ The precedence for determining implementation files to return is:
42374238

42384239
(defun projectile-find-matching-test (impl-file)
42394240
"Compute the name of the test matching IMPL-FILE."
4240-
(when-let ((candidates (projectile--find-matching-test impl-file)))
4241+
(when-let* ((candidates (projectile--find-matching-test impl-file)))
42414242
(projectile--choose-from-candidates candidates :caller 'projectile-read-file)))
42424243

42434244
(defun projectile-find-matching-file (test-file)
42444245
"Compute the name of a file matching TEST-FILE."
4245-
(when-let ((candidates (projectile--find-matching-file test-file)))
4246+
(when-let* ((candidates (projectile--find-matching-file test-file)))
42464247
(projectile--choose-from-candidates candidates :caller 'projectile-read-file)))
42474248

42484249
(defun projectile-grep-default-files ()

test/projectile-test.el

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,32 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
352352
(expect (projectile-ignored-file-p "/path/to/project/TAGS") :to-be-truthy)
353353
(expect (projectile-ignored-file-p "/path/to/project/foo.el") :not :to-be-truthy)))
354354

355+
(describe "projectile-globally-ignored-files"
356+
(it "includes TAGS file by default"
357+
(expect (member projectile-tags-file-name projectile-globally-ignored-files) :to-be-truthy))
358+
(it "includes cache file by default"
359+
(expect (member projectile-cache-file projectile-globally-ignored-files) :to-be-truthy))
360+
(it "causes cache file to be ignored via projectile-ignored-file-p"
361+
(spy-on 'projectile-ignored-files :and-return-value
362+
(list (concat "/path/to/project/" projectile-cache-file)
363+
(concat "/path/to/project/" projectile-tags-file-name)))
364+
(expect (projectile-ignored-file-p (concat "/path/to/project/" projectile-cache-file)) :to-be-truthy)
365+
(expect (projectile-ignored-file-p "/path/to/project/source.el") :not :to-be-truthy)))
366+
367+
(describe "projectile-globally-ignored-files :safe predicate"
368+
(it "accepts list of strings as safe"
369+
(let ((pred (get 'projectile-globally-ignored-files 'safe-local-variable)))
370+
(expect (funcall pred '("file1" "file2")) :to-be-truthy)))
371+
(it "rejects list containing non-strings as unsafe"
372+
(let ((pred (get 'projectile-globally-ignored-files 'safe-local-variable)))
373+
(expect (funcall pred '("file1" 123)) :not :to-be-truthy)))
374+
(it "accepts empty list as safe"
375+
(let ((pred (get 'projectile-globally-ignored-files 'safe-local-variable)))
376+
(expect (funcall pred '()) :to-be-truthy)))
377+
(it "rejects non-list as unsafe"
378+
(let ((pred (get 'projectile-globally-ignored-files 'safe-local-variable)))
379+
(expect (funcall pred "not-a-list") :not :to-be-truthy))))
380+
355381
(describe "projectile-ignored-files"
356382
(it "returns list of ignored files"
357383
(spy-on 'projectile-project-root :and-return-value "/path/to/project")
@@ -365,6 +391,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
365391
(projectile-ignored-files '("TAGS" "file\d+\\.log")))
366392
(expect (projectile-ignored-files) :not :to-equal files)
367393
(expect (projectile-ignored-files) :to-equal '("/path/to/project/TAGS"
394+
"/path/to/project/.projectile-cache.eld"
368395
"/path/to/project/foo.js"
369396
"/path/to/project/bar.rb")))))
370397

0 commit comments

Comments
 (0)