Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError for baseIndentLevel: 1 option and vue file in indentation #5657

Merged
merged 3 commits into from Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/rules/declaration-bang-space-before/__tests__/index.js
@@ -1,5 +1,7 @@
'use strict';

const postcssSass = require('postcss-sass');

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -197,7 +199,7 @@ testRule({
testRule({
ruleName,
config: ['always'],
syntax: 'sass',
customSyntax: postcssSass,
skipBasicChecks: true,
fix: true,

Expand All @@ -215,7 +217,7 @@ testRule({
testRule({
ruleName,
config: ['never'],
syntax: 'sass',
customSyntax: postcssSass,
skipBasicChecks: true,
fix: true,

Expand Down
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -79,11 +81,10 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [true],
skipBasicChecks: true,
syntax: 'html',
customSyntax: postcssHtml,

accept: [
{
Expand Down
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -265,11 +267,10 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [true],
skipBasicChecks: true,
syntax: 'html',
customSyntax: postcssHtml,

accept: [
{
Expand Down
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -109,10 +111,9 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [true],
syntax: 'html',
customSyntax: postcssHtml,

accept: [
{
Expand Down
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -87,10 +89,9 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [true],
syntax: 'html',
customSyntax: postcssHtml,

accept: [
{
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/declaration-empty-line-before/__tests__/index.js
@@ -1,5 +1,6 @@
'use strict';

const postcssHtml = require('postcss-html')();
const postcssLess = require('postcss-less');
const postcssScss = require('postcss-scss');
const stripIndent = require('common-tags').stripIndent;
Expand Down Expand Up @@ -904,7 +905,7 @@ testRule({
skip: true,
ruleName,
config: ['always'],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,
accept: [
{
Expand Down Expand Up @@ -962,7 +963,7 @@ testRule({
skip: true,
ruleName,
config: ['always', { ignore: ['inside-single-line-block'] }],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/function-url-no-scheme-relative/__tests__/index.js
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -117,10 +119,9 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [true],
syntax: 'html',
customSyntax: postcssHtml,

reject: [
{
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/function-url-quotes/__tests__/index.js
@@ -1,5 +1,7 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
Expand Down Expand Up @@ -613,10 +615,9 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: ['always'],
syntax: 'html',
customSyntax: postcssHtml,

reject: [
{
Expand Down
17 changes: 7 additions & 10 deletions lib/rules/indentation/__tests__/html.js
@@ -1,12 +1,13 @@
'use strict';

const postcssHtml = require('postcss-html')();

const { messages, ruleName } = require('..');

testRule({
skip: true,
ruleName,
config: ['tab'],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down Expand Up @@ -191,10 +192,9 @@ a {
});

testRule({
skip: true,
ruleName,
config: [2],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down Expand Up @@ -242,15 +242,14 @@ a {
});

testRule({
skip: true,
ruleName,
config: [
'tab',
{
baseIndentLevel: 1,
},
],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down Expand Up @@ -388,15 +387,14 @@ a {
});

testRule({
skip: true,
ruleName,
config: [
'tab',
{
baseIndentLevel: 0,
},
],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down Expand Up @@ -484,15 +482,14 @@ a {
});

testRule({
skip: true,
ruleName,
config: [
2,
{
baseIndentLevel: 1,
},
],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/indentation/index.js
Expand Up @@ -664,7 +664,7 @@ function inferRootIndentLevel(root, baseIndentLevel, indentSize) {
if (document) {
const nextRoot = document.nodes[document.nodes.indexOf(root) + 1];

afterEnd = nextRoot ? nextRoot.raws.beforeStart : document.raws.afterEnd;
afterEnd = nextRoot ? nextRoot.raws.codeBefore : document.raws.codeAfter;
} else {
// Nested root node in css-in-js lang
const parent = root.parent;
Expand All @@ -673,13 +673,13 @@ function inferRootIndentLevel(root, baseIndentLevel, indentSize) {

const nextRoot = parent.nodes[parent.nodes.indexOf(root) + 1];

afterEnd = nextRoot ? nextRoot.raws.beforeStart : root.raws.afterEnd;
afterEnd = nextRoot ? nextRoot.raws.codeBefore : root.raws.codeAfter;
}
} else {
afterEnd = after;
}

indents.push(afterEnd.match(/^[ \t]*/)[0]);
if (afterEnd) indents.push(afterEnd.match(/^[ \t]*/)[0]);
}

if (indents.length) {
Expand Down
21 changes: 19 additions & 2 deletions lib/rules/max-empty-lines/__tests__/index.js
@@ -1,5 +1,6 @@
'use strict';

const postcssHtml = require('postcss-html')();
const postcssScss = require('postcss-scss');
const sugarss = require('sugarss');

Expand Down Expand Up @@ -152,20 +153,24 @@ testRule({
});

testRule({
skip: true,
ruleName,
config: [1],
syntax: 'html',
customSyntax: postcssHtml,
fix: true,

accept: [
{
code: `<div>




<style>
/* horse */
</style>



</div>`,
},
{
Expand Down Expand Up @@ -207,6 +212,7 @@ a {color: pink;}
<style>
/* horse */


</style>
</div>`,
fixed: `<div>
Expand All @@ -223,6 +229,7 @@ a {color: pink;}
{
code: `<div style="color: pink;


">
</div>`,
fixed: `<div style="color: pink;
Expand All @@ -242,6 +249,7 @@ a {}
<style>
a {}


</style>
</div>`,
fixed: `<div style="color: pink;">
Expand Down Expand Up @@ -273,10 +281,17 @@ testRule({
code: `
import styled from 'styled-components';





export default styled.div\`
color: #00
\`;




`,
},
{
Expand Down Expand Up @@ -310,6 +325,7 @@ import styled from 'styled-components';
export default styled.div\`
/* horse */


color: #00
\`;
`,
Expand Down Expand Up @@ -337,6 +353,7 @@ export const style1 = styled.div\`
export const style2 = styled.div\`
color: #00


\`;`,
fixed: `
import styled from 'styled-components';
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/max-empty-lines/index.js
Expand Up @@ -195,15 +195,15 @@ function isEofNode(document, root) {

// @ts-expect-error -- TS2367: This condition will always return 'false' since the types 'Root' and 'ChildNode | undefined' have no overlap.
if (root === document.last) {
after = document.raws && document.raws.afterEnd;
after = document.raws && document.raws.codeAfter;
} else {
// @ts-expect-error -- TS2345: Argument of type 'Root' is not assignable to parameter of type 'number | ChildNode'.
const rootIndex = document.index(root);

const nextNode = document.nodes[rootIndex + 1];

// @ts-expect-error -- TS2339: Property 'beforeStart' does not exist on type 'AtRuleRaws | RuleRaws | DeclarationRaws | CommentRaws'.
after = nextNode && nextNode.raws && nextNode.raws.beforeStart;
// @ts-expect-error -- TS2339: Property 'codeBefore' does not exist on type 'CommentRaws'.
after = nextNode && nextNode.raws && nextNode.raws.codeBefore;
}

return !String(after).trim();
Expand Down