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

Update .travis.yml #358

Merged
merged 2 commits into from
May 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ sudo: false

language: node_js

node_js: node # lastest
node_js:
- "10.15.3"

cache: yarn

Expand Down
4 changes: 2 additions & 2 deletions src/formatter/formatReactElementNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import spacer from './spacer';
import formatTreeNode from './formatTreeNode';
import formatProp from './formatProp';
import mergeSiblingPlainStringChildrenReducer from './mergeSiblingPlainStringChildrenReducer';
import propNameSorter from './propNameSorter';
import sortPropsByNames from './sortPropsByNames';
import type { Options } from './../options';
import type { ReactElementTreeNode } from './../tree';

Expand Down Expand Up @@ -137,7 +137,7 @@ export default (
.filter(defaultPropName => !visibleAttributeNames.includes(defaultPropName))
.forEach(defaultPropName => visibleAttributeNames.push(defaultPropName));

const attributes = visibleAttributeNames.sort(propNameSorter(sortProps));
const attributes = sortPropsByNames(sortProps)(visibleAttributeNames);

attributes.forEach(attributeName => {
const {
Expand Down
23 changes: 0 additions & 23 deletions src/formatter/propNameSorter.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/formatter/propNameSorter.spec.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/formatter/sortPropsByNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* @flow */

const isKeyOrRefProps = (propName: string) => ['key', 'ref'].includes(propName);

export default (shouldSortUserProps: boolean) => (
props: string[]
): string[] => {
const haveKeyProp = props.includes('key');
const haveRefProp = props.includes('ref');

const userPropsOnly = props.filter(oneProp => !isKeyOrRefProps(oneProp));

const sortedProps = shouldSortUserProps
? [...userPropsOnly.sort()] // We use basic lexical order
: [...userPropsOnly];

if (haveRefProp) {
sortedProps.unshift('ref');
}

if (haveKeyProp) {
sortedProps.unshift('key');
}

return sortedProps;
};
27 changes: 27 additions & 0 deletions src/formatter/sortPropsByNames.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* @flow */

import sortPropsByNames from './sortPropsByNames';

test('sortPropsByNames should always move the `key` and `ref` keys first', () => {
const fixtures = ['c', 'key', 'a', 'ref', 'b'];

expect(sortPropsByNames(false)(fixtures)).toEqual([
'key',
'ref',
'c',
'a',
'b',
]);
});

test('sortPropsByNames should always sort the props and keep `key` and `ref` keys first', () => {
const fixtures = ['c', 'key', 'a', 'ref', 'b'];

expect(sortPropsByNames(true)(fixtures)).toEqual([
'key',
'ref',
'a',
'b',
'c',
]);
});