editorconfig-core-js icon indicating copy to clipboard operation
editorconfig-core-js copied to clipboard

Ability to retrieve the current configuration file path

Open xavierfoucrier opened this issue 4 years ago • 7 comments

Currently, there is no way to know which .editorconfig file is used when getting the configuration using parseSync: if we try to load the configuration from a path when there is no .editorconfig file, the package will travel through the file system to search for another .editorconfig file and finally retrieve the read configuration.

It should be great to be able to retrieve the configuration file name or file path to know which file is currently used.

xavierfoucrier avatar Oct 31 '19 11:10 xavierfoucrier

There may be more than one .editorconfig file that was merged into the final configuration, so it would have to be a list of files.

jednano avatar Oct 31 '19 14:10 jednano

Hi @jedmao,

You are right, I am OK with that :wink: Thanks for the fix.

xavierfoucrier avatar Oct 31 '19 14:10 xavierfoucrier

@xavierfoucrier see https://github.com/cto-af/editorconfig-core-js/pull/7 and see if this API would work for you. I put an array of applied file paths in a editorconfig.FILES symbol on the returned object. Many uses of the object will just ignore the symbol, and you can look for it if you want it:

> ec.parseSync('foo')
{
  indent_style: 'space',
  indent_size: 2,
  end_of_line: 'lf',
  charset: 'utf-8',
  trim_trailing_whitespace: true,
  insert_final_newline: true,
  block_comment_start: '/**',
  block_comment: '*',
  block_comment_end: '*/',
  tab_width: 2,
  [Symbol(FILES)]: [ '<my path>/.editorconfig' ]
}

I'd be happy to make a dedicated API instead (to guarantee backward-compat), but this seems like a good compromise to me.

hildjj avatar Sep 03 '22 20:09 hildjj

@hildjj thanks for the fix, unfortunately I have no time right now to check.

I will also prefer to check implementation on the official editorconfig project instead. Feel free to make a PR on the editorconfig-core-js repo :wink:

xavierfoucrier avatar Sep 05 '22 07:09 xavierfoucrier

I'll prepare a PR for this repo after I've gotten a few other things cleared up.

hildjj avatar Sep 05 '22 16:09 hildjj

@xavierfoucrier See #107 please. I'm interested in feedback before I merge it.

hildjj avatar Oct 10 '22 21:10 hildjj

@hildjj unfortunately no time on my side for that right now, sorry.

xavierfoucrier avatar Oct 11 '22 06:10 xavierfoucrier

@hildjj Finally, I took the time to have a look: it works great! Thanks for the fix :tada:

xavierfoucrier avatar Oct 20 '22 14:10 xavierfoucrier