Skip to content

Commit 084e2e2

Browse files
committed
Add Prettier
1 parent 5df9896 commit 084e2e2

17 files changed

+274
-372
lines changed

.eslintrc.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
2-
"extends": "eslint-config-hudochenkov",
2+
"extends": [
3+
"eslint-config-hudochenkov",
4+
"eslint-config-prettier"
5+
],
6+
"plugins": [
7+
"prettier"
8+
],
39
"env": {
410
"browser": false,
511
"node": true,
@@ -9,5 +15,16 @@
915
"globals": {
1016
"groupTest": true,
1117
"runTest": true
18+
},
19+
"rules": {
20+
"prettier/prettier": [
21+
"error",
22+
{
23+
"printWidth": 100,
24+
"useTabs": true,
25+
"singleQuote": true,
26+
"trailingComma": "es5"
27+
}
28+
]
1229
}
1330
}

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const order = require('./lib/order');
77
const propertiesOrder = require('./lib/properties-order');
88
const validateOptions = require('./lib/validateOptions');
99

10-
module.exports = postcss.plugin('postcss-sorting', function (opts) {
11-
return function (css) {
10+
module.exports = postcss.plugin('postcss-sorting', function(opts) {
11+
return function(css) {
1212
plugin(css, opts);
1313
};
1414
});
@@ -17,7 +17,8 @@ function plugin(css, opts) {
1717
const validatedOptions = validateOptions(opts);
1818

1919
if (validatedOptions !== true) {
20-
if (console && console.warn && _.isString(validatedOptions)) { // eslint-disable-line no-console
20+
// eslint-disable-next-line no-console
21+
if (console && console.warn && _.isString(validatedOptions)) {
2122
console.warn(validatedOptions); // eslint-disable-line no-console
2223
}
2324

jest-setup.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ const path = require('path');
55
const plugin = require('./');
66
const postcss = require('postcss');
77

8-
global.groupTest = function (testGroups) {
9-
testGroups.forEach((group) => {
10-
group.cases.forEach((item) => {
11-
const message = item.description || group.message || `Should work with ${JSON.stringify(group.options)}`;
8+
global.groupTest = function(testGroups) {
9+
testGroups.forEach(group => {
10+
group.cases.forEach(item => {
11+
const message =
12+
item.description || group.message || `Should work with ${JSON.stringify(group.options)}`;
1213
const testFn = item.only ? test.only : test;
1314

14-
testFn(
15-
message,
16-
() => postcss(plugin(group.options))
15+
testFn(message, () =>
16+
postcss(plugin(group.options))
1717
.process(item.fixture)
18-
.then((root) => {
18+
.then(root => {
1919
expect(root.css).toEqual(item.expected);
2020
})
2121
);
2222
});
2323
});
2424
};
2525

26-
global.runTest = function (input, opts, dirname) {
26+
global.runTest = function(input, opts, dirname) {
2727
const dir = path.join(dirname, './fixtures/');
2828
const inputSplitted = input.split('.');
2929
let inputName = input;
@@ -53,8 +53,9 @@ global.runTest = function (input, opts, dirname) {
5353
fs.writeFileSync(expectPath, expectCSS);
5454
}
5555

56-
return postcss([plugin(opts)]).process(inputCSS)
57-
.then((result) => {
56+
return postcss([plugin(opts)])
57+
.process(inputCSS)
58+
.then(result => {
5859
const actualCSS = result.css;
5960

6061
fs.writeFileSync(actualPath, actualCSS);

lib/__tests__/test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict';
22

3-
test(
4-
`Should do nothing if config is undefined`,
5-
() => runTest('empty-lines-preserve', undefined, __dirname)
6-
);
3+
test(`Should do nothing if config is undefined`, () =>
4+
runTest('empty-lines-preserve', undefined, __dirname));

lib/__tests__/validate-options.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ testConfig({
5050
description: 'valid keywords',
5151
valid: true,
5252
config: {
53-
order: [
54-
'custom-properties',
55-
'dollar-variables',
56-
'declarations',
57-
'rules',
58-
'at-rules',
59-
],
53+
order: ['custom-properties', 'dollar-variables', 'declarations', 'rules', 'at-rules'],
6054
},
6155
});
6256

@@ -126,9 +120,7 @@ testConfig({
126120
description: 'invalid keyword',
127121
valid: false,
128122
config: {
129-
order: [
130-
'custom-property',
131-
],
123+
order: ['custom-property'],
132124
},
133125
});
134126

@@ -317,20 +309,15 @@ testConfig({
317309
description: 'valid. default order (one property)',
318310
valid: true,
319311
config: {
320-
'properties-order': [
321-
'color',
322-
],
312+
'properties-order': ['color'],
323313
},
324314
});
325315

326316
testConfig({
327317
description: 'valid. default order (two properties)',
328318
valid: true,
329319
config: {
330-
'properties-order': [
331-
'color',
332-
'display',
333-
],
320+
'properties-order': ['color', 'display'],
334321
},
335322
});
336323

@@ -340,9 +327,7 @@ testConfig({
340327
config: {
341328
'properties-order': [
342329
{
343-
properties: [
344-
'color',
345-
],
330+
properties: ['color'],
346331
},
347332
'display',
348333
],

lib/calcAtRulePatternPriority.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ module.exports = function calcAtRulePatternPriority(pattern, node) {
3030
}
3131

3232
// doesn't have `name` and `hasBlock`
33-
if (!pattern.hasOwnProperty('hasBlock') && !pattern.hasOwnProperty('name') && !pattern.hasOwnProperty('paremeter')) {
33+
if (
34+
!pattern.hasOwnProperty('hasBlock') &&
35+
!pattern.hasOwnProperty('name') &&
36+
!pattern.hasOwnProperty('paremeter')
37+
) {
3438
priority = 1;
3539
}
3640

@@ -45,7 +49,12 @@ module.exports = function calcAtRulePatternPriority(pattern, node) {
4549
}
4650

4751
// patter has `name`, `parameter`, and `hasBlock`, but it doesn't match all properties
48-
if (pattern.hasOwnProperty('name') && pattern.hasOwnProperty('parameter') && pattern.hasOwnProperty('hasBlock') && priority < 30000) {
52+
if (
53+
pattern.hasOwnProperty('name') &&
54+
pattern.hasOwnProperty('parameter') &&
55+
pattern.hasOwnProperty('hasBlock') &&
56+
priority < 30000
57+
) {
4958
priority = 0;
5059
}
5160

lib/createExpectedOrder.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@ module.exports = function createExpectedOrder(input) {
66
const order = {};
77
let position = 0;
88

9-
input.forEach((item) => {
9+
input.forEach(item => {
1010
position += 1;
1111

12-
if (
13-
_.isString(item)
14-
&& item !== 'at-rules'
15-
&& item !== 'rules'
16-
) {
12+
if (_.isString(item) && item !== 'at-rules' && item !== 'rules') {
1713
order[item] = {
1814
position,
1915
};
2016
}
2117

22-
if (
23-
item === 'rules'
24-
|| item.type === 'rule'
25-
) {
18+
if (item === 'rules' || item.type === 'rule') {
2619
// Convert 'rules' into extended pattern
2720
if (item === 'rules') {
2821
item = {
@@ -50,10 +43,7 @@ module.exports = function createExpectedOrder(input) {
5043
order[item.type].push(nodeData);
5144
}
5245

53-
if (
54-
item === 'at-rules'
55-
|| item.type === 'at-rule'
56-
) {
46+
if (item === 'at-rules' || item.type === 'at-rule') {
5747
// Convert 'at-rules' into extended pattern
5848
if (item === 'at-rules') {
5949
item = {

lib/createExpectedPropertiesOrder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function createExpectedPropertiesOrder(input) {
99
let propertyIndex = 0;
1010

1111
input.forEach((group, groupIndex) => {
12-
group.properties.forEach((property) => {
12+
group.properties.forEach(property => {
1313
order[property] = {
1414
propertyIndex,
1515
groupIndex,

lib/getComments.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,10 @@ function afterDeclaration(comments, nextNode, nodeData, currentInitialIndex) {
9797
// add a marker
9898
nextNode.sortProperty = true;
9999

100-
return afterDeclaration(comments.concat(commentData), nextNode.next(), nodeData, commentData.initialIndex);
100+
return afterDeclaration(
101+
comments.concat(commentData),
102+
nextNode.next(),
103+
nodeData,
104+
commentData.initialIndex
105+
);
101106
}

lib/getOrderData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function getOrderData(expectedOrder, node) {
3030
let prioritizedPattern;
3131
let max = 0;
3232

33-
rules.forEach(function (pattern) {
33+
rules.forEach(function(pattern) {
3434
const priority = calcRulePatternPriority(pattern, nodeType);
3535

3636
if (priority > max) {
@@ -65,7 +65,7 @@ module.exports = function getOrderData(expectedOrder, node) {
6565
let prioritizedPattern;
6666
let max = 0;
6767

68-
atRules.forEach(function (pattern) {
68+
atRules.forEach(function(pattern) {
6969
const priority = calcAtRulePatternPriority(pattern, nodeType);
7070

7171
if (priority > max) {

0 commit comments

Comments
 (0)