Skip to content

Commit

Permalink
Feat 41279 Fix parsing of line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronicusUA committed May 13, 2024
1 parent 795aabd commit 2bff09e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { EOL } from 'os';

import replaceComponentsWithSlots from '../utils/replaceComponentsWithSlots';

/**
Expand All @@ -13,12 +11,5 @@ export default function transformer(file, api, options) {

replaceComponentsWithSlots(j, { root, componentName: 'Popper' });

// I've tried { lineTerminator } option here, but still get wrong line endings on my Windows machine
const result = root.toSource(printOptions);

if (EOL !== '\n') {
return result.replace(/\n/g, EOL);
}

return result;
return root.toSource(printOptions);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'path';
import { expect } from 'chai';
import { EOL } from 'os';

import { jscodeshift } from '../../../testUtils';
import transform from './popper-props';
import readFile from '../../util/readFile';
Expand All @@ -12,14 +14,30 @@ describe('@mui/codemod', () => {
describe('deprecations', () => {
describe('popper-props', () => {
it('transforms props as needed', () => {
const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {});
const actual = transform(
{ source: read('./test-cases/actual.js') },
{ jscodeshift },
{
printOptions: {
lineTerminator: EOL,
},
},
);

const expected = read('./test-cases/expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent', () => {
const actual = transform({ source: read('./test-cases/expected.js') }, { jscodeshift }, {});
const actual = transform(
{ source: read('./test-cases/expected.js') },
{ jscodeshift },
{
printOptions: {
lineTerminator: EOL,
},
},
);

const expected = read('./test-cases/expected.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
Expand All @@ -31,7 +49,12 @@ describe('@mui/codemod', () => {
const actual = transform(
{ source: read('./test-cases/theme.actual.js') },
{ jscodeshift },
{ printOptions: { trailingComma: false } },
{
printOptions: {
trailingComma: false,
lineTerminator: EOL,
},
},
);

const expected = read('./test-cases/theme.expected.js');
Expand All @@ -42,7 +65,11 @@ describe('@mui/codemod', () => {
const actual = transform(
{ source: read('./test-cases/theme.expected.js') },
{ jscodeshift },
{},
{
printOptions: {
lineTerminator: EOL,
},
},
);

const expected = read('./test-cases/theme.expected.js');
Expand Down

0 comments on commit 2bff09e

Please sign in to comment.