Skip to content

Commit

Permalink
[ARGG-741]: Add rule to set alphabetical order of imports (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
olliecurtis authored Oct 17, 2023
1 parent a77afec commit b41bbef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ module.exports = {
},
],
pathGroupsExcludedImportTypes: ['react', 'react-dom', 'prop-types'],
alphabetize: {
order: 'asc',
},
},
],

Expand Down
14 changes: 14 additions & 0 deletions test/order-fail.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable no-unused-vars,import/no-unresolved,import/extensions */
// import/order
import ReactDom from 'react-dom';

Check failure on line 3 in test/order-fail.jsx

View workflow job for this annotation

GitHub Actions / Run-Tests / Test

`react-dom` import should occur after import of `react`

Check failure on line 3 in test/order-fail.jsx

View workflow job for this annotation

GitHub Actions / Run-Tests / Test

`react-dom` import should occur after import of `react`
import PropTypes from 'prop-types';
import { Component, Fragment } from 'react';

import { fontSizeSm } from '@skyscanner/bpk-foundations-web/tokens/base.es6';

Check failure on line 7 in test/order-fail.jsx

View workflow job for this annotation

GitHub Actions / Run-Tests / Test

`@skyscanner/bpk-foundations-web/tokens/base.es6` import should occur after import of `@skyscanner/backpack-web/bpk-component-link`

Check failure on line 7 in test/order-fail.jsx

View workflow job for this annotation

GitHub Actions / Run-Tests / Test

`@skyscanner/bpk-foundations-web/tokens/base.es6` import should occur after import of `@skyscanner/backpack-web/bpk-component-link`
import ArrowUpIcon from '@skyscanner/backpack-web/bpk-component-icon/sm/long-arrow-up';
import BpkButton from '@skyscanner/backpack-web/bpk-component-button';
import BpkButtonLink from '@skyscanner/backpack-web/bpk-component-link';

import Component1 from '../Component1';
import Component2 from '../../Component2';
/* eslint-enable no-unused-vars,import/no-unresolved,import/extensions */
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"test:fail-bpk": "echo 'Expecting failure' && eslint bpk-token-fail.jsx; if [ $? -eq 1 ]; then exit 0; fi",
"test:fail-prettier": "echo 'Expecting failure' && eslint prettier-fail.jsx; if [ $? -eq 1 ]; then exit 0; fi",
"test:fail-react": "echo 'Expecting failure' && eslint react-fail.tsx; if [ $? -eq 1 ]; then exit 0; fi",
"test": "npm run test:pass && npm run test:fail-jsdoc && npm run test:fail-bpk && npm run test:fail-prettier && npm run test:fail-react"
"test:fail-import-order": "echo 'Expecting failure' && eslint order-fail.jsx; if [ $? -eq 1 ]; then exit 0; fi",
"test": "npm run test:pass && npm run test:fail-jsdoc && npm run test:fail-bpk && npm run test:fail-prettier && npm run test:fail-react && npm run test:fail-import-order"
},
"dependencies": {
"prop-types": "^15.5.10",
Expand Down
6 changes: 3 additions & 3 deletions test/pass.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import ReactDom from 'react-dom';

import ExternalLibrary from 'external-library';

import { fontSizeSm } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
import BpkButton from 'bpk-component-button';
import ArrowUpIcon from 'bpk-component-icon/sm/long-arrow-up';
import BpkButton from '@skyscanner/backpack-web/bpk-component-button';
import ArrowUpIcon from '@skyscanner/backpack-web/bpk-component-icon/sm/long-arrow-up';
import BpkButtonLink from '@skyscanner/backpack-web/bpk-component-link';
import { fontSizeSm } from '@skyscanner/bpk-foundations-web/tokens/base.es6';

import SomeCommonFunctionality from 'common/some-functionality';

Expand Down

0 comments on commit b41bbef

Please sign in to comment.