Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
fix: use local stylelint for config resolution if available
Browse files Browse the repository at this point in the history
Although the running of stylelint was changed to use the local project's
instance if available in #381, the instance used to determine the
configuration was unfortunately left as the bundled version. This made
no difference then, and made no difference when the bundled version was
still compatible with the local project one... but caused issues when
there is a mismatch.

This fixes it so we always use the stylelint instance local to the
project if there is one available, falling back to the bundled one if
one isn't available.

Fixes #440.
  • Loading branch information
Arcanemagus committed Feb 4, 2020
1 parent b598700 commit 21c1d7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export function refreshModulesPath(modulesDir) {
}

function getProjectDir(filePath) {
if (!filePath) {
// No file (e.g. in the specs)
return null;
}
const projectDir = atom.project.relativizePath(filePath)[0];
return projectDir !== null ? projectDir : path.dirname(filePath);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import hasValidScope from './validate';
// Dependencies
let helpers;
let dirname;
let stylelint;

function loadDeps() {
if (!helpers) {
Expand All @@ -16,9 +15,6 @@ function loadDeps() {
if (!dirname) {
({ dirname } = require('path'));
}
if (!stylelint) {
stylelint = require('stylelint');
}
}

export default {
Expand Down Expand Up @@ -156,6 +152,8 @@ export default {
}

helpers.startMeasure('linter-stylelint: Create Linter');
// Use the project local stylelint to resolve the config if one exists
const stylelint = await helpers.getStylelintInstance();
const stylelintLinter = await stylelint.createLinter();
helpers.endMeasure('linter-stylelint: Create Linter');

Expand Down

0 comments on commit 21c1d7f

Please sign in to comment.