Skip to content

Commit

Permalink
Merge branch 'add-media-query-no-invalid--amiable-lynx-a9e08fec44' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/stylelint/stylelint into add-media-query-no-invalid--amiable-lynx-a9e08fec44
  • Loading branch information
romainmenke committed Jun 24, 2023
2 parents 64dc211 + 0ee3221 commit e28036e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 109 deletions.
@@ -1,16 +1,20 @@
'use strict';
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import { readFile } from 'node:fs/promises';

const cp = require('child_process');
const fs = require('fs');
const path = require('path');
import rules from '../index.js';

const rules = require('..');
const ruleEntries = Object.entries(rules);
const require = createRequire(import.meta.url);
const __dirname = fileURLToPath(new URL('.', import.meta.url));

const ruleEntries = Object.entries(rules);
let rulesListDoc;

beforeAll(async () => {
rulesListDoc = await fs.promises.readFile(
rulesListDoc = await readFile(
path.join(__dirname, '..', '..', '..', 'docs', 'user-guide', 'rules.md'),
'utf8',
);
Expand All @@ -32,21 +36,21 @@ describe('fixable rules', () => {
const fixableRules = ruleEntries.filter(([, rule]) => rule.meta.fixable);

test.each(fixableRules)('"%s" should describe fixable in the rules doc', async (name) => {
const doc = await fs.promises.readFile(path.join(__dirname, '..', name, 'README.md'), 'utf8');
const doc = await readFile(path.join(__dirname, '..', name, 'README.md'), 'utf8');

expect(doc).toMatch('`fix` option');
});

test.each(fixableRules)('"%s" should describe fixable in the rules doc', (name) => {
expect(rulesListDoc).toMatch(new RegExp(`^.+\\b${name}\\b.+\\|.+\\|\\s+🔧\\s+\\|$`, 'm'));
expect(rulesListDoc).toMatch(new RegExp(`^.+\`${name}\`.+\\|.+\\|\\s+🔧\\s+\\|$`, 'm'));
});
});

describe('deprecated rules', () => {
const deprecatedRules = ruleEntries.filter(([, rule]) => rule.meta.deprecated);

test.each(deprecatedRules)('"%s" should describe deprecation in the rules doc', async (name) => {
const doc = await fs.promises.readFile(path.join(__dirname, '..', name, 'README.md'), 'utf8');
const doc = await readFile(path.join(__dirname, '..', name, 'README.md'), 'utf8');

expect(doc).toMatch('> **Warning**');
});
Expand All @@ -57,40 +61,49 @@ describe('custom message option', () => {
'"%s" should describe a custom message option in its doc',
async (ruleName) => {
const jsFile = path.join(__dirname, '..', ruleName, 'index.js');
const jsCode = await fs.promises.readFile(jsFile, 'utf8');
const jsCode = await readFile(jsFile, 'utf8');

// NOTE: If all rules support a custom message option, we should remove this `if` statement.
if (!jsCode.includes('\tmessageArgs: [')) return;

const doc = await fs.promises.readFile(jsFile.replace('index.js', 'README.md'), 'utf8');
const doc = await readFile(jsFile.replace('index.js', 'README.md'), 'utf8');

expect(doc).toContain('`message` secondary option');
},
);
});

describe('standard config', () => {
const cwd = path.join(__dirname, 'tmp');
const tmpDir = path.join(__dirname, 'tmp');

fs.rmSync(cwd, { recursive: true, force: true });
fs.mkdirSync(cwd, { recursive: true });
fs.writeFileSync(path.join(cwd, 'package.json'), '{}');
cp.execSync(
// NOTE: The use of Promised-based APIs may cause flaky test on CI.
rmSync(tmpDir, { recursive: true, force: true });
mkdirSync(tmpDir, { recursive: true });
writeFileSync(path.join(tmpDir, 'package.json'), '{}');
execSync(
'npm install --silent --no-package-lock --no-audit --omit=peer stylelint-config-standard',
{ cwd },
{ cwd: tmpDir },
);

const configRules = (name) => Object.keys(require(path.join(cwd, 'node_modules', name)).rules);
const configRules = (name) => {
const config = require(path.join(tmpDir, 'node_modules', name));

return Object.keys(config.rules);
};

const standardRules = configRules('stylelint-config-standard');

test('standard config is not empty', () => {
standardRules.push(...configRules('stylelint-config-recommended'));

afterAll(() => {
rmSync(tmpDir, { recursive: true, force: true });
});

test('the rules are not empty', () => {
expect(standardRules).not.toHaveLength(0);
});

test.each(standardRules)(
'"%s" should be included in the standard config in the rules doc',
(name) => {
expect(rulesListDoc).toMatch(new RegExp(`^.+\\b${name}\\b.+\\|\\s+✅\\s+\\|.+\\|$`, 'm'));
},
);
test.each(standardRules)('the rule "%s" are present in the rules doc', (name) => {
expect(rulesListDoc).toMatch(new RegExp(`^.+\`${name}\`.+\\|\\s+✅\\s+\\|.+\\|$`, 'm'));
});
});
9 changes: 0 additions & 9 deletions lib/utils/__tests__/blurComments.test.js

This file was deleted.

11 changes: 0 additions & 11 deletions lib/utils/__tests__/blurFunctionArguments.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions lib/utils/blurComments.js

This file was deleted.

53 changes: 0 additions & 53 deletions lib/utils/blurFunctionArguments.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -47,6 +47,7 @@
"pretest": "npm run lint",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test-coverage": "npm test --ignore-scripts -- --coverage",
"test-only": "npm test --ignore-scripts",
"version": "changeset version",
"postversion": "git restore package.json",
"watch": "npm test --ignore-scripts -- --watch",
Expand Down

0 comments on commit e28036e

Please sign in to comment.