Skip to content

Commit

Permalink
feat(stylelint): deprecated stylistic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
deot committed Dec 7, 2023
1 parent c140864 commit cb98871
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 15 deletions.
67 changes: 62 additions & 5 deletions packages/stylelint/__tests__/index.spec.ts
Expand Up @@ -9,20 +9,77 @@ const lint = async (text: string) => {
return resultObject;
};

describe('index.ts', () => {
describe('index.js', () => {
it('success', async () => {
expect.hasAssertions();
try {
const data = await lint(`a { color: red; }\n`);
const data = await lint(`a { color: inherit; }\n`);
expect(data.errored).toBe(false);
} catch (e) {
console.log(e);
}
});

it('declaration-block-trailing-semicolon', async () => {
it('single line comments', async () => {
expect.hasAssertions();
const data = await lint(`a { color: red }`);
expect(data.output).toMatch('declaration-block-trailing-semicolon');
const data = await lint(`// allow`);
expect(data.errored).toBe(false);
});

it('stylelint-config-standard-scss', async () => {
expect.hasAssertions();
const data = await lint(`
@use 'sass:meta';
@function color($value) {
@return if(meta.type-of($value) == 'string', $value, 'inherit');
}
a { color: color(1); }
`);
expect(data.errored).toBe(false);
});

it('unit-no-unknown, rpx', async () => {
expect.hasAssertions();
const data = await lint(`a { font-size: 12rpx; }`);
expect(data.errored).toBe(false);
});

it('unit-no-unknown, xxx disallow', async () => {
expect.hasAssertions();
const data = await lint(`a { font-size: 12xxx; }`);
expect(data.errored).toBe(true);
});

it('stylelint-order', async () => {
expect.hasAssertions();
const data = await lint(`a { bottom: 2px; top: 1px; }`);
expect(data.output).toMatch('Expected \\"top\\" to come before \\"bottom\\" (order/properties-order)');
});
});

/**
* https://stylelint.io/migration-guide/to-15
* 代码风格的提示已经移除, 现在都不会校正了;
* 包含
* 1. 结尾需要分号
* 2. 缩进
* 3. ....
*/
describe('deprecated', () => {
it('semicolon', async () => {
expect.hasAssertions();
const data = await lint(`a { color: inherit }`);
expect(data.errored).toBe(false);
});

it('indentation', async () => {
expect.hasAssertions();
const data = await lint(`a {\n color: inherit \n}`);
expect(data.errored).toBe(false);
});
});



7 changes: 1 addition & 6 deletions packages/stylelint/index.js
@@ -1,9 +1,8 @@
module.exports = {
root: true,
plugins: ['stylelint-order'],
extends: ['stylelint-config-standard'],
extends: ['stylelint-config-standard-scss'],
rules: {
"indentation": "tab",
'selector-pseudo-class-no-unknown': [
true,
{
Expand Down Expand Up @@ -32,12 +31,8 @@ module.exports = {
],
'no-empty-source': null,
'named-grid-areas-no-invalid': null,
'unicode-bom': 'never',
'no-descending-specificity': null,
'font-family-no-missing-generic-family-keyword': null,
'declaration-colon-space-after': 'always-single-line',
'declaration-colon-space-before': 'never',
'declaration-block-trailing-semicolon': 'always',
'rule-empty-line-before': [
'always',
{
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint/package.json
Expand Up @@ -10,7 +10,7 @@
"access": "public"
},
"dependencies": {
"stylelint-config-standard": "^34.0.0",
"stylelint-config-standard-scss": "^11.1.0",
"stylelint-order": "^6.0.3"
},
"devDependencies": {
Expand Down
63 changes: 60 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb98871

Please sign in to comment.