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

Commit

Permalink
Merge pull request #355 from AtomLinter/arcanemagus/stricter-specs
Browse files Browse the repository at this point in the history
Stop relying on useStandard in all the specs
  • Loading branch information
Arcanemagus authored Jul 17, 2017
2 parents e83677b + b0bd7ce commit 98febbc
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 48 deletions.
5 changes: 5 additions & 0 deletions spec/fixtures/good/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"block-no-empty": true
}
}
8 changes: 6 additions & 2 deletions spec/fixtures/ignore-files/.stylelintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"ignoreFiles": ["styles.css"],
"rules": { "block-no-empty": true }
"ignoreFiles": [
"styles.css"
],
"rules": {
"block-no-empty": true
}
}
5 changes: 5 additions & 0 deletions spec/fixtures/invalid/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"block-no-empty": true
}
}
5 changes: 5 additions & 0 deletions spec/fixtures/less/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"block-no-empty": true
}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions spec/fixtures/postcss/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"block-no-empty": true
}
}
5 changes: 5 additions & 0 deletions spec/fixtures/sugarss/.stylelintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"number-leading-zero": "always"
}
}
79 changes: 33 additions & 46 deletions spec/linter-stylelint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@ import * as path from 'path';
// eslint-disable-next-line no-unused-vars, import/no-extraneous-dependencies
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';

const badDir = path.join(__dirname, 'fixtures', 'bad');
const configStandardPath = path.join(badDir, 'stylelint-config-standard.css');
const warn = path.join(__dirname, 'fixtures', 'warn', 'warn.css');
const good = path.join(__dirname, 'fixtures', 'good', 'good.css');
const ignorePath = path.join(__dirname, 'fixtures', 'ignore-files', 'styles.css');
const invalidPath = path.join(__dirname, 'fixtures', 'invalid', 'invalid.css');
const invalidRulePath = path.join(__dirname, 'fixtures', 'invalid-rule', 'styles.css');
const invalidExtendsPath = path.join(__dirname, 'fixtures', 'invalid-extends', 'styles.css');
const invalidConfigPath = path.join(__dirname, 'fixtures', 'invalid-config', 'styles.css');
const lessDir = path.join(__dirname, 'fixtures', 'less');
const goodLess = path.join(lessDir, 'good.less');
const configStandardLessPath = path.join(lessDir, 'stylelint-config-standard.less');
const goodPostCSS = path.join(__dirname, 'fixtures', 'postcss', 'styles.pcss');
const issuesPostCSS = path.join(__dirname, 'fixtures', 'postcss', 'issues.pcss');
const goodSugarSS = path.join(__dirname, 'fixtures', 'sugarss', 'good.sss');
const badSugarSS = path.join(__dirname, 'fixtures', 'sugarss', 'bad.sss');
const fixtures = path.join(__dirname, 'fixtures');
const configStandardPath = path.join(fixtures, 'bad', 'stylelint-config-standard.css');
const warningPath = path.join(fixtures, 'warn', 'warn.css');
const invalidRulePath = path.join(fixtures, 'invalid-rule', 'styles.css');

const blockNoEmpty = 'Unexpected empty block (<a href="http://stylelint.io/user-guide/rules/block-no-empty">block-no-empty</a>)';

Expand All @@ -28,14 +16,13 @@ describe('The stylelint provider for Linter', () => {

beforeEach(async () => {
atom.workspace.destroyActivePaneItem();
atom.config.set('linter-stylelint.useStandard', true);

await atom.packages.activatePackage('language-css');
await atom.packages.activatePackage('linter-stylelint');
});

it('bundles and works with stylelint-config-standard', async () => {
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
atom.config.set('linter-stylelint.useStandard', true);
const editor = await atom.workspace.open(configStandardPath);
const messages = await lint(editor);
expect(messages.length).toBeGreaterThan(0);
Expand All @@ -50,8 +37,7 @@ describe('The stylelint provider for Linter', () => {
});

it('reports rules set as warnings as a Warning', async () => {
atom.config.set('linter-stylelint.useStandard', false);
const editor = await atom.workspace.open(warn);
const editor = await atom.workspace.open(warningPath);
const messages = await lint(editor);

expect(messages.length).toBeGreaterThan(0);
Expand All @@ -66,13 +52,14 @@ describe('The stylelint provider for Linter', () => {
});

it('finds nothing wrong with a valid file', async () => {
const editor = await atom.workspace.open(good);
const goodPath = path.join(fixtures, 'good', 'good.css');
const editor = await atom.workspace.open(goodPath);
const messages = await lint(editor);
expect(messages.length).toBe(0);
});

it('shows CSS syntax errors with an invalid file', async () => {
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
const invalidPath = path.join(fixtures, 'invalid', 'invalid.css');
const editor = await atom.workspace.open(invalidPath);
const messages = await lint(editor);
expect(messages.length).toBe(1);
Expand All @@ -87,7 +74,6 @@ describe('The stylelint provider for Linter', () => {

it('shows an error on non-fatal stylelint runtime error', async () => {
const text = 'Unexpected option value "foo" for rule "block-no-empty"';
atom.config.set('linter-stylelint.useStandard', false);
const editor = await atom.workspace.open(invalidRulePath);
const messages = await lint(editor);
expect(messages.length).toBe(1);
Expand All @@ -101,7 +87,8 @@ describe('The stylelint provider for Linter', () => {
});

it('shows an error notification for a fatal stylelint runtime error', async () => {
atom.config.set('linter-stylelint.useStandard', false);
const invalidExtendsPath = path.join(fixtures, 'invalid-extends', 'styles.css');

spyOn(atom.notifications, 'addError').andCallFake(() => ({}));
const addError = atom.notifications.addError;

Expand All @@ -117,7 +104,8 @@ describe('The stylelint provider for Linter', () => {
});

it('shows an error notification with a broken syntax configuration', async () => {
atom.config.set('linter-stylelint.useStandard', false);
const invalidConfigPath = path.join(fixtures, 'invalid-config', 'styles.css');

spyOn(atom.notifications, 'addError').andCallFake(() => ({}));
const addError = atom.notifications.addError;

Expand All @@ -133,7 +121,6 @@ describe('The stylelint provider for Linter', () => {
});

it('disables when no configuration file is found', async () => {
atom.config.set('linter-stylelint.disableWhenNoConfig', true);
spyOn(atom.notifications, 'addError').andCallFake(() => ({}));

const editor = await atom.workspace.open(configStandardPath);
Expand All @@ -143,9 +130,7 @@ describe('The stylelint provider for Linter', () => {
});

describe('ignores files when files are specified in ignoreFiles and', () => {
beforeEach(() => {
atom.config.set('linter-stylelint.useStandard', true);
});
const ignorePath = path.join(fixtures, 'ignore-files', 'styles.css');

it('shows a message when asked to', async () => {
atom.config.set('linter-stylelint.showIgnored', true);
Expand All @@ -170,35 +155,35 @@ describe('The stylelint provider for Linter', () => {
});

it("doesn't persist settings across runs", async () => {
atom.config.set('linter-stylelint.useStandard', true);
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
// The config for this folder breaks the block-no-empty rule
const invalidEditor = await atom.workspace.open(invalidRulePath);
await lint(invalidEditor);

// While this file uses that rule
const editor = await atom.workspace.open(configStandardPath);
const editor = await atom.workspace.open(warningPath);
const messages = await lint(editor);
expect(messages.length).toBeGreaterThan(0);

// test only the first error
expect(messages[0].type).toBe('Error');
expect(messages[0].severity).toBe('error');
expect(messages[0].type).toBe('Warning');
expect(messages[0].severity).toBe('warning');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toBe(blockNoEmpty);
expect(messages[0].filePath).toBe(configStandardPath);
expect(messages[0].filePath).toBe(warningPath);
expect(messages[0].range).toEqual([[0, 5], [0, 7]]);
});

describe('works with Less files and', () => {
const lessDir = path.join(fixtures, 'less');
const goodLess = path.join(lessDir, 'good.less');
const badLess = path.join(lessDir, 'bad.less');

beforeEach(async () => {
atom.config.set('linter-stylelint.useStandard', true);
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
await atom.packages.activatePackage('language-less');
});

it('works with stylelint-config-standard', async () => {
const editor = await atom.workspace.open(configStandardLessPath);
it('shows lint messages when found', async () => {
const editor = await atom.workspace.open(badLess);
const messages = await lint(editor);
expect(messages.length).toBeGreaterThan(0);

Expand All @@ -207,7 +192,7 @@ describe('The stylelint provider for Linter', () => {
expect(messages[0].severity).toBe('error');
expect(messages[0].text).not.toBeDefined();
expect(messages[0].html).toBe(blockNoEmpty);
expect(messages[0].filePath).toBe(configStandardLessPath);
expect(messages[0].filePath).toBe(badLess);
expect(messages[0].range).toEqual([[0, 5], [0, 7]]);
});

Expand All @@ -219,13 +204,14 @@ describe('The stylelint provider for Linter', () => {
});

describe('works with PostCSS files and', () => {
const goodPostCSS = path.join(fixtures, 'postcss', 'styles.pcss');
const issuesPostCSS = path.join(fixtures, 'postcss', 'issues.pcss');

beforeEach(async () => {
atom.config.set('linter-stylelint.useStandard', true);
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
await atom.packages.activatePackage('language-postcss');
});

it('works with stylelint-config-standard', async () => {
it('shows lint messages when found', async () => {
const editor = await atom.workspace.open(issuesPostCSS);
const messages = await lint(editor);
expect(messages.length).toBeGreaterThan(0);
Expand All @@ -247,13 +233,14 @@ describe('The stylelint provider for Linter', () => {
});

describe('works with SugarSS files and', () => {
const goodSugarSS = path.join(fixtures, 'sugarss', 'good.sss');
const badSugarSS = path.join(fixtures, 'sugarss', 'bad.sss');

beforeEach(async () => {
atom.config.set('linter-stylelint.useStandard', true);
atom.config.set('linter-stylelint.disableWhenNoConfig', false);
await atom.packages.activatePackage('language-postcss');
});

it('works with stylelint-config-standard', async () => {
it('shows lint messages when found', async () => {
const nlzMessage = 'Expected a leading zero (<a href="http://stylelint.io/user-guide/rules/number-leading-zero">number-leading-zero</a>)';
const editor = await atom.workspace.open(badSugarSS);
const messages = await lint(editor);
Expand Down

0 comments on commit 98febbc

Please sign in to comment.