Skip to content

Commit

Permalink
Remove workaround for #4119
Browse files Browse the repository at this point in the history
  • Loading branch information
hudochenkov committed Apr 6, 2020
1 parent 0cf46bc commit 6abe618
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 68 deletions.
40 changes: 1 addition & 39 deletions lib/lintSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,47 +257,9 @@ function createEmptyPostcssResult(filePath) {
* @param {PostcssResult} postcssResult
* @returns {boolean}
*/
function isFixCompatible({ stylelint, root }) {
function isFixCompatible({ stylelint }) {
// Check for issue #2643
if (stylelint.disabledRanges.all.length) return false;

// Check for issue #4119
if (root && root.source && root.source.lang === 'jsx' && root.nodes) {
// Gather all locations of template literals
/**
* @typedef TemplateLiteralLocation
* @type {object}
* @property {number} startLine - Start of the template literal.
* @property {number} endLine - End of the template literal
*/
/** @type {Array<TemplateLiteralLocation>} */
const templateLiteralLocations = [];

root.nodes.forEach((n) => {
if (n.source && n.source.start && n.source.input.css !== undefined) {
templateLiteralLocations.push({
startLine: n.source.start.line,
endLine: n.source.start.line + n.source.input.css.split('\n').length,
});
}
});

// Compare all different template literal locations with eachother
for (const location1 of templateLiteralLocations) {
for (const location2 of templateLiteralLocations) {
// Make sure it's not the same template literal
if (location1 !== location2) {
// The first location should be before or after the second location.
// If not, it's not compatible.
if (
!(location1.endLine < location2.startLine || location2.endLine < location1.startLine)
) {
return false;
}
}
}
}
}

return true;
}
29 changes: 0 additions & 29 deletions system-tests/fix/fix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,6 @@ describe('fix', () => {
expect(result.output).toBe(code);
});
});

it("doesn't fix with nested template literals", () => {
const code = `
import styled, { css } from 'styled-components';
const Component = styled.div\`
padding: 10px;
\${() => css\`
color: #b02d00;
\`}
\`;
`;

return stylelint
.lint({
code,
syntax: 'css-in-js',
config: {
rules: {
indentation: 2,
},
},
fix: true,
})
.then((result) => {
expect(result.errored).toBe(true);
expect(result.output).toBe(code);
});
});
});

describe('fix with BOM', () => {
Expand Down

0 comments on commit 6abe618

Please sign in to comment.