diff --git a/linter.py b/linter.py index d1cf736..d0fd600 100644 --- a/linter.py +++ b/linter.py @@ -16,6 +16,19 @@ from SublimeLinter.lint import NodeLinter +def get_config_file(): + """ + Get the valid configuration file, as per the list of configuration files supported by ESLint. + + This function iterates through a list of valid file names and check if the file actually exists. If it + does then return its name. If none of the file names exist then return the default value .eslintrc. + Refer: http://eslint.org/docs/user-guide/configuring#configuration-file-formats. + """ + + file_names = ['.eslintrc.js', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.json', '.eslintrc', 'package.json'] + return next((name for name in file_names if os.path.isfile(name)), '.eslintrc') + + class Eslint_d(NodeLinter): """Provides an interface to eslint_d.""" @@ -41,7 +54,7 @@ class Eslint_d(NodeLinter): selectors = { 'html': 'source.js.embedded.html' } - config_file = ('--config', '.eslintrc', '~') + config_file = ('--config', get_config_file(), '~') def find_errors(self, output): """