editorconfig / editorconfig-core-js

EditorConfig Core library and command line utility written in JavaScript
http://editorconfig.org
MIT License
271 stars 48 forks source link

Ability to ignore path when included from external source #32

Closed localjo closed 8 years ago

localjo commented 8 years ago

This started out as me tracking down what I thought was a bug in gulp-lintspaces or node-lintspaces. Here is a thread that describes most of my issue: https://github.com/schorfES/node-lintspaces/issues/30

But it turns out, this may be more of a feature request, or at least a request for clarification. My ultimate goal is to use this gulp task to apply .editorconfig rules from a project dependency to my projects themselves;

var gulp = require('gulp');
var lintspaces = require("gulp-lintspaces");

...

gulp.task('lint', function() {
  return gulp.src('**/*')
    .pipe(lintspaces({
      editorconfig: './node_modules/@myorg/code-standards/.editorconfig'
    }))
    .pipe(lintspaces.reporter());
});

But I found that this gulp task doesn't apply the rules to all of the files in the gulp.src glob, but only if they're in the same subdirectory as the .editorconfig file specified in the task. I tracked that behavior down to this line https://github.com/editorconfig/editorconfig-core-js/blob/master/editorconfig.js#L87. It seems this is by design, based on how .editorconfig's default behavior is scoped. However, when including an .editorconfig file from a dependency using something like gulp-lintspaces, it would be nice to be able to override this default behavior and make the .editorconfig settings apply to everything in the gulp.src. That could probably be done with some sort of key passed into the options parameter for the editorconfig.parse() function, like global: true, or maybe the root key can already be used here to achieve what I want, with only slight, or no, modification.

localjo commented 8 years ago

Maybe this line: https://github.com/editorconfig/editorconfig-core-js/blob/master/editorconfig.js#L114

Could become something like;

var pathPrefix = '';
if (options.root !== '/') { pathPrefix = path.dirname(file.name); }

Willing to open a PR, but I'm not sure if this suggestion is completely misunderstanding or trying to apply this code to a situation it's not designed for.

jednano commented 8 years ago

I'm curious if creating a sym link to ./node_modules/@myorg/code-standards/.editorconfig in your project root would provide the functionality that you need?

jednano commented 8 years ago

BTW – your code snippet looks like it would only cover *nix environments.

localjo commented 8 years ago

For our use case we ended up using https://github.com/AlbertoElias/gulp-lintspaces with it's built in options and we're maintaining a separate .editorconfig file. It's less than ideal to maintain the code standards for our org in multiple places, but since they don't change often, if ever, it's an acceptable compromise for us. The symlink solution opens up a whole can of worms of making sure that the symlinks are properly created when cloning the project across platforms. Closing this issue because the overhead to find a solution that works is higher than it's worth.