Skip to content

Commit

Permalink
Style fixes for the ESLint upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Jul 3, 2017
1 parent bbbbb09 commit fefa33f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 36 deletions.
14 changes: 7 additions & 7 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export default function transformPostCSS({ types: t }: any): any {

if (tokens !== undefined) {
const expression = path.findParent((test) => (
test.isVariableDeclaration() ||
test.isVariableDeclaration() ||
test.isExpressionStatement()
));
));

expression.addComment(
'trailing', ` @related-file ${stylesheetPath}`, true
Expand All @@ -120,16 +120,16 @@ export default function transformPostCSS({ types: t }: any): any {
if (tokens) {
const styles = t.objectExpression(
Object.keys(tokens).map(
(token) => t.objectProperty(
t.stringLiteral(token),
t.stringLiteral(tokens[token])
)
(token) => t.objectProperty(
t.stringLiteral(token),
t.stringLiteral(tokens[token])
)
)
);
/* eslint-disable new-cap */

const variableDeclaration = t.VariableDeclaration('var',
[t.VariableDeclarator(path.node.specifiers[0].local, styles)]);
[t.VariableDeclarator(path.node.specifiers[0].local, styles)]);

/* eslint-enable new-cap */
path.addComment('trailing', ` @related-file ${stylesheetPath}`, true);
Expand Down
2 changes: 1 addition & 1 deletion src/postcss-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const main = async function main(...args: string[]): Promise<void> {

/* istanbul ignore if */
if ((require: any).main === module) {
(async (): Promise<void> => {
(async(): Promise<void> => {
try { await main(...process.argv.slice(2)); }
catch (err) { process.stderr.write(`${err.stack}\n`); process.exit(1); }
})();
Expand Down
4 changes: 2 additions & 2 deletions src/postcss-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const main = async function main(
data += chunk.toString('utf8');
});

connection.on('end', async (): Promise<void> => {
connection.on('end', async(): Promise<void> => {
try {
let tokens, cache;
const { cssFile } = JSON.parse(data);
Expand Down Expand Up @@ -139,7 +139,7 @@ const main = async function main(

/* istanbul ignore if */
if ((require: any).main === module) {
(async (): Promise<void> => {
(async(): Promise<void> => {
try { await main(...process.argv.slice(2)); }
catch (err) { process.stderr.write(`${err.stack}\n`); process.exit(1); }
})();
Expand Down
7 changes: 4 additions & 3 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export const babelNoModules = {
presets: [ ['env', { modules: false, targets: { node: 'current' } }] ],
};

export const transform = (filename: string,
babelOptionOverrides: ?{ [string]: mixed }
): Promise<string> => {
export const transform = (
filename: string,
babelOptionOverrides: ?{ [string]: mixed },
): Promise<string> => {
const file = path.join(fixtures, filename);

const options = Object.assign({
Expand Down
18 changes: 9 additions & 9 deletions test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ describe('babel-plugin-transform-postcss', () => {
describe('when transforming require.js', () => {
let result;

beforeEach(async () => { result = await transform('require.js'); });
beforeEach(async() => { result = await transform('require.js'); });

it('launches the server', testServerLaunched);
it('launches a client', () => testClientLaunched('simple.css'));
it('compiles correctly', async () => {
it('compiles correctly', async() => {
expect(result).to.eql((await read('require.expected.js')).trim());
});

Expand All @@ -107,11 +107,11 @@ describe('babel-plugin-transform-postcss', () => {
describe('when transforming import.js', () => {
let result;

beforeEach(async () => { result = await transform('import.js'); });
beforeEach(async() => { result = await transform('import.js'); });

it('launches the server', testServerLaunched);
it('launches a client', () => testClientLaunched('simple.css'));
it('compiles correctly', async () => {
it('compiles correctly', async() => {
expect(result).to.eql((await read('import.expected.js')).trim());
});

Expand Down Expand Up @@ -157,15 +157,15 @@ describe('babel-plugin-transform-postcss', () => {
describe('when transforming import.js without modules', () => {
let result;

beforeEach(async () => {
beforeEach(async() => {
result = await transform('import.js', babelNoModules);
});

it('launches the server', testServerLaunched);
it('launches a client', () => testClientLaunched('simple.css'));
it('compiles correctly', async () => {
it('compiles correctly', async() => {
expect(result).to.eql(
(await read('import.no.modules.expected.js')).trim()
(await read('import.no.modules.expected.js')).trim()
);
});

Expand All @@ -181,9 +181,9 @@ describe('babel-plugin-transform-postcss', () => {
let result;

beforeEach(() => childProcess.execFileSync.returns(new Buffer('')));
beforeEach(async () => { result = await transform('require.js'); });
beforeEach(async() => { result = await transform('require.js'); });

it('compiles correctly', async () => {
it('compiles correctly', async() => {
expect(result).to.eql((await read('require.expected.empty.js')).trim());
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/postcss-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('postcss-client', () => {
});
});

afterEach(async () => {
afterEach(async() => {
await new Promise((resolve: () => void, reject: (Error) => void) => {
fs.unlinkSync(testSocket);
server.close((err: ?Error) => {
Expand All @@ -84,7 +84,7 @@ describe('postcss-client', () => {
});

describe('main(...testArgs)', () => {
beforeEach(async () => {
beforeEach(async() => {
const write = new Promise((resolve: () => void) => {
streams.stdout.on('finish', () => resolve());
});
Expand All @@ -107,7 +107,7 @@ describe('postcss-client', () => {
});

describe('main(...testArgs)', () => {
beforeEach(async () => { await main(testSocket, 'client message'); });
beforeEach(async() => { await main(testSocket, 'client message'); });

it('attempts to re-connect', () => {
expect(net.connect).to.have.been.calledTwice;
Expand Down
22 changes: 11 additions & 11 deletions test/postcss-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const testTmp = join(__dirname, 'tmp');

describe('postcss-server', () => {
let server, originalStderr;
const invokeMain = async () => { server = await main(testSocket, testTmp); };
const invokeMain = async() => { server = await main(testSocket, testTmp); };
const closeServer = async() => {
await new Promise((resolve: () => void, reject: (Error) => void) => {
server.close((err: ?Error) => {
Expand All @@ -40,7 +40,7 @@ describe('postcss-server', () => {
});
});
};
const closeStderr = async () => {
const closeStderr = async() => {
const write = new Promise((resolve: () => void) => {
streams.stderr.on('finish', () => resolve());
});
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('postcss-server', () => {
});

const simpleCSSFile = join(__dirname, 'fixtures', 'simple.css');
const sendMessage = async (
const sendMessage = async(
json: {
cssFile: string,
}
Expand All @@ -113,15 +113,15 @@ describe('postcss-server', () => {
return response;
};

it('accepts JSON details and extracts PostCSS modules', async () => {
it('accepts JSON details and extracts PostCSS modules', async() => {
const response = await sendMessage({
cssFile: simpleCSSFile,
});

expect(JSON.parse(response)).to.eql({ simple: '_simple_jvai8_1' });
});

it('fails gracefully for invalid CSS', async () => {
it('fails gracefully for invalid CSS', async() => {
const response = await sendMessage({
cssFile: join(__dirname, 'fixtures', 'invalid.css'),
});
Expand All @@ -139,7 +139,7 @@ describe('postcss-server', () => {
}));
});

it('accepts JSON details and extracts PostCSS modules', async () => {
it('accepts JSON details and extracts PostCSS modules', async() => {
const response = await sendMessage({
cssFile: simpleCSSFile,
});
Expand All @@ -156,7 +156,7 @@ describe('postcss-server', () => {

fs.writeFileSync(path.join(testTmp, `${name}.cache`), 'not-json');
});
beforeEach(async () => {
beforeEach(async() => {
response = await sendMessage({
cssFile: simpleCSSFile,
});
Expand All @@ -176,7 +176,7 @@ describe('postcss-server', () => {
describe('with a missing CSS file', () => {
let response;

beforeEach(async () => {
beforeEach(async() => {
response = await sendMessage({
cssFile: join(__dirname, 'fixtures', 'nofile'),
});
Expand All @@ -199,7 +199,7 @@ describe('postcss-server', () => {
beforeEach(() => stub(path, 'dirname').callsFake(() => process.cwd()));
afterEach(() => path.dirname.restore());

beforeEach(async () => {
beforeEach(async() => {
response = await sendMessage({
cssFile: join(__dirname, 'fixtures', 'simple.css'),
configFile: join(__dirname, 'fixtures', 'nofile'),
Expand All @@ -226,7 +226,7 @@ describe('postcss-server', () => {
});
afterEach(() => { Server.prototype.listen.restore(); });

it('fails to complete main(...testArgs)', async () => {
it('fails to complete main(...testArgs)', async() => {
let error;

try { await invokeMain(); }
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('postcss-server', () => {
beforeEach(() => { stub(fs, 'mkdirSync').throws('Error with no code'); });
afterEach(() => { fs.mkdirSync.restore(); });

it('errors when invoking main', async () => {
it('errors when invoking main', async() => {
let error;

try { await invokeMain(); }
Expand Down

0 comments on commit fefa33f

Please sign in to comment.