Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #744 from Shopify/stylelint-config-test
Browse files Browse the repository at this point in the history
Add config tests for stylelint
  • Loading branch information
t-kelly authored Sep 11, 2018
2 parents c9dde0e + 8d70f7b commit 9906033
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/slate-tools/slate-tools.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ module.exports = {
'stylelint.bin': path.resolve(__dirname, 'node_modules/.bin/stylelint'),

// Path to .stylelintrc file
'stylelint.rc': (config) =>
'stylelint.config': (config) =>
path.resolve(config.get('paths.theme'), '.stylelintrc'),

// Path to .stylelintignore file
'stylelint.ignore': (config) =>
'stylelint.ignorePath': (config) =>
path.resolve(config.get('paths.theme'), '.stylelintignore'),

// Path to Themelint bin executable
Expand Down
28 changes: 26 additions & 2 deletions packages/slate-tools/tools/stylelint/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('stylelint()', () => {
execSync.mockClear();
});

test('executes the stylelint bin from slate-tools/node-modules directory', () => {
test(`executes the stylelint bin from the path specified in the 'stylelint.bin' config`, () => {
const {stylelint} = require('../index');
const SlateConfig = require('@shopify/slate-config');
const config = new SlateConfig(require('../../../slate-tools.schema'));
Expand All @@ -19,7 +19,31 @@ describe('stylelint()', () => {
);
});

test('executes ESLint with the --fix flag', () => {
test(`executes stylelint with the --config flag set to 'stylelint.config' config`, () => {
const {stylelint} = require('../index');
const SlateConfig = require('@shopify/slate-config');
const config = new SlateConfig(require('../../../slate-tools.schema'));
stylelint();
expect(execSync).toHaveBeenCalledWith(
expect.stringContaining(`--config ${config.get('stylelint.config')}`),
expect.anything(),
);
});

test(`executes stylelint with the --ignore-path flag set to 'stylelint.ignorePath' config`, () => {
const {stylelint} = require('../index');
const SlateConfig = require('@shopify/slate-config');
const config = new SlateConfig(require('../../../slate-tools.schema'));
stylelint();
expect(execSync).toHaveBeenCalledWith(
expect.stringContaining(
`--ignore-path ${config.get('stylelint.ignorePath')}`,
),
expect.anything(),
);
});

test('executes stylelint with the --fix flag', () => {
const {stylelint} = require('../index');
stylelint({fix: true});
expect(execSync).toHaveBeenCalledWith(
Expand Down
13 changes: 8 additions & 5 deletions packages/slate-tools/tools/stylelint/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const execSync = require('child_process').execSync;
const SlateConfig = require('@shopify/slate-config');

Expand All @@ -7,13 +8,15 @@ function stylelint({fix} = {}) {
const executable = config.get('stylelint.bin');
const fixFlag = fix ? '--fix' : '';
const glob = `./**/*.{${['css', 'scss', 'sass'].join(',')}}`;
const ignorePatterns = ['dist', 'node_modules'].reduce(
(buffer, pattern) => `${buffer} --ignore-pattern ${pattern}`,
'',
);
const stylelintConfig = `--config ${config.get('stylelint.config')}`;
const ignorePath = fs.existsSync(config.get('stylelint.ignorePath'))
? `--ignore-path ${config.get('stylelint.ignorePath')}`
: '';

execSync(
`${JSON.stringify(executable)} "${glob}" ${ignorePatterns} ${fixFlag}`,
`${JSON.stringify(
executable,
)} "${glob}" ${stylelintConfig} ${fixFlag} ${ignorePath}`,
{
stdio: 'inherit',
},
Expand Down

0 comments on commit 9906033

Please sign in to comment.