Permalink
Browse files

Use the new getConfigForFile function

stylelint 7.4.0 introduced a new function allowing us to request it to
generate the configuration from a file path in the same manner as it would
do for itself. Use this to generate the configuration instead of
attempting to do so ourselves.

Closes #289.
  • Loading branch information...
1 parent 7b8177f commit e3b00791575565d40063744a46c6c0fdec4128ce @Arcanemagus Arcanemagus committed Oct 12, 2016
Showing with 17 additions and 20 deletions.
  1. +16 −18 lib/index.js
  2. +0 −1 package.json
  3. +1 −1 spec/linter-stylelint-spec.js
View
@@ -14,7 +14,6 @@ const { dirname } = lazyReq('path')('dirname');
const stylelint = lazyReq('stylelint');
const { rangeFromLineNumber } = lazyReq('atom-linter')('rangeFromLineNumber');
const assignDeep = lazyReq('assign-deep');
-const cosmiconfig = lazyReq('cosmiconfig');
const escapeHTML = lazyReq('escape-html');
// Settings
@@ -271,27 +270,26 @@ export function provideLinter() {
options.config.rules['declaration-block-trailing-semicolon'] = null;
}
- startMeasure('linter-stylelint: Cosmiconfig');
- const cosmiconfigOptions = {
- cwd: dirname(filePath),
- rcExtensions: true // Allow extensions on rc filenames
- };
+ startMeasure('linter-stylelint: Config');
let foundConfig;
+ const stylelintLinter = await stylelint().createLinter();
try {
- foundConfig = await cosmiconfig()('stylelint', cosmiconfigOptions);
+ foundConfig = await stylelintLinter.getConfigForFile(filePath);
} catch (error) {
- endMeasure('linter-stylelint: Cosmiconfig');
- // If we got here, cosmiconfig failed to parse the configuration
- // there's no point of re-linting if useStandard is true, because the
- // user does not have the complete set of desired rules parsed
- atom.notifications.addError('Unable to parse stylelint configuration', {
- detail: error.message,
- dismissable: true
- });
- endMeasure('linter-stylelint: Lint');
- return [];
+ if (!/No configuration provided for .+/.test(error.message)) {
+ endMeasure('linter-stylelint: Config');
+ // If we got here, stylelint failed to parse the configuration
+ // there's no point of re-linting if useStandard is true, because the
+ // user does not have the complete set of desired rules parsed
+ atom.notifications.addError('Unable to parse stylelint configuration', {
+ detail: error.message,
+ dismissable: true
+ });
+ endMeasure('linter-stylelint: Lint');
+ return [];
+ }
}
- endMeasure('linter-stylelint: Cosmiconfig');
+ endMeasure('linter-stylelint: Config');
if (foundConfig) {
options.config = assignDeep()(rules, foundConfig.config);
View
@@ -54,7 +54,6 @@
"assign-deep": "^0.4.5",
"atom-linter": "^8.0.0",
"atom-package-deps": "^4.0.1",
- "cosmiconfig": "^1.1.0",
"escape-html": "^1.0.3",
"lazy-req": "^1.1.0",
"stylelint": "7.4.2",
@@ -123,7 +123,7 @@ describe('The stylelint provider for Linter', () => {
const args = addError.mostRecentCall.args;
expect(addError.calls.length).toBe(1);
- expect(args[0]).toBe('Unable to run stylelint');
+ expect(args[0]).toBe('Unable to parse stylelint configuration');
expect(args[1].detail).toContain('Could not find "some-module-that-will-never-exist".');
expect(args[1].dismissable).toBe(true);
})

0 comments on commit e3b0079

Please sign in to comment.