Subject: Re: bug#78097: 30.1; editorconfig can pass nil to file-name-directory

From: "Peter J. Jones" <[email-masked]>
Date: Sun, 04 May 2025 14:21:39 +0200

On Sat, May 03 2025, Stefan Monnier wrote:
>> When a function called from
>> `editorconfig-get-local-variables-functions' returns an alist, but
>> there is no .editorconfig file in the directory tree,
>
> Could you give a concrete example of how this can happen?

Yes.  I want to have `delete-trailing-whitespace' in a `before-save'
hook by default but still allow editor config to remove it if
"trim_trailing_whitespace" is set to false in the current project.  So I
wrote the following function and put it in
`editorconfig-get-local-variables-functions':

(defun pjones:editorconfig-apply-trim-whitespace (props)
  "Conditionally change the trim_trailing_whitespace setting.

Enable whitespace trimming unless the editor configuration file
explicitly disables it.  PROPS is the hash from the editor configuration
file."
  (when (null (gethash 'trim_trailing_whitespace props))
    (puthash 'trim_trailing_whitespace "true" props)
    (editorconfig--get-trailing-ws props)))

Projects that don't have editor configuration files trigger the bug
where nil is passed to `file-name-directory'.

Thank you.