Skip to content

Commit

Permalink
fix: linitng errors and plugins test
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenisx committed Nov 20, 2022
1 parent 1de50e6 commit 0bff714
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions lib/__tests__/plugins.test.js
Expand Up @@ -39,6 +39,14 @@ const configRelativeAndExtendRelative = {
},
};

const configPluginRequire = {
plugins: [require('./fixtures/plugin-warn-about-foo')],
rules: {
'plugin/warn-about-foo': 'always',
'block-no-empty': true,
},
};

const processorRelative = postcss().use(
stylelint({ config: configRelative, configBasedir: __dirname }),
);
Expand All @@ -52,6 +60,7 @@ const processorRelativeAndExtendRelative = postcss().use(
configBasedir: __dirname,
}),
);
const processorPluginRequire = postcss().use(stylelint({ config: configPluginRequire }));

it('one plugin runs', async () => {
const result = await processorRelative.process(cssWithFoo, { from: undefined });
Expand Down Expand Up @@ -108,6 +117,39 @@ it('config with its own plugins extending another config that invokes a plugin w
expect(result.warnings()[0].node).toBeTruthy();
});

it('plugin with CJS require()', async () => {
const result = await processorPluginRequire.process(cssWithFoo, { from: undefined });

expect(result.warnings()).toHaveLength(2);
expect(result.warnings()[0].text).toBe('found .foo (plugin/warn-about-foo)');
expect(result.warnings()[1].text).toBe('Unexpected empty block (block-no-empty)');
expect(result.warnings()[0].node).toBeTruthy();
});

it('plugin with ESM import()', async () => {
const result = await postcss()
.use(
stylelint({
config: {
// Following object mocks `await import()` style imports, since
// jest without node --experimental-vm-modules enabled fails to
// support dynamic ESM imports.
plugins: [{ default: require('./fixtures/plugin-warn-about-foo') }], // Similar to `await import()`
rules: {
'plugin/warn-about-foo': 'always',
'block-no-empty': true,
},
},
}),
)
.process(cssWithFoo, { from: undefined });

expect(result.warnings()).toHaveLength(2);
expect(result.warnings()[0].text).toBe('found .foo (plugin/warn-about-foo)');
expect(result.warnings()[1].text).toBe('Unexpected empty block (block-no-empty)');
expect(result.warnings()[0].node).toBeTruthy();
});

describe('plugin using exposed rules via stylelint.rules', () => {
const cssWithDirectiveLower = '/** @@check-color-hex-case */ a { color: #eee; }';
const cssWithDirectiveUpper = '/** @@check-color-hex-case */ a { color: #EEE; }';
Expand Down
4 changes: 2 additions & 2 deletions types/stylelint/index.d.ts
Expand Up @@ -7,10 +7,10 @@ declare module 'stylelint' {
export type Severity = 'warning' | 'error';

export type ConfigExtends = string | string[];
export type PluginImportType =
export type PluginType =
| { default?: { ruleName: string; rule: Rule } }
| { ruleName: string; rule: Rule };
export type ConfigPlugins = string | string[] | PluginImportType | PluginImportType[];
export type ConfigPlugins = string | PluginType | (string | PluginType)[];
export type ConfigProcessor = string | [string, Object];
export type ConfigProcessors = string | ConfigProcessor[];
export type ConfigIgnoreFiles = string | string[];
Expand Down

0 comments on commit 0bff714

Please sign in to comment.