question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[order] pathGroup doesn't appear to work

See original GitHub issue

Problem

I am configuring pathGroups, but they do not appear to be working. No matter the group I set for the pattern, it always requires that it appear at the top of the external imports. I’ve manually verified that minimatch is returning the correct output for some of the test paths that I’m working with.

tsconfig.json

"compilerOptions": {
   ...
   "paths": {
     "@/*": ["./*"]
   }
}

.eslintrc.js

  'import/order': [
    'error',
    {
      groups: ['builtin', 'external', ['sibling', 'parent'], 'index', 'internal', 'object'],
      pathGroups: [
        {
          pattern: '@/**',
          group: 'internal',
        },
      ],
      'newlines-between': 'always',
      alphabetize: {
        order: 'asc',
        caseInsensitive: true,
      },
    },
  ],

Expected

import { StatusCodes } from 'http-status-codes';
import { Route, useRouter } from 'next-router-provider';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

import { useSession } from '@/client/providers/session';
import { pageRoutes } from '@/client/routes';

Actual

import { useSession } from '@/client/providers/session';
import { pageRoutes } from '@/client/routes';
import { StatusCodes } from 'http-status-codes';
import { Route, useRouter } from 'next-router-provider';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import styled from 'styled-components';

versions

eslint 7.22.0
eslint-plugin-import 2.22.1
typescript 4.2.3

minimatch outputs (both of which are correct)

> minimatch('@/client/types', '@/**')
true
> minimatch('@external-package/foo-package', '@/**')
false

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
nickzeleicommented, Mar 17, 2021

@Jack-Barry I’ve been testing and it looks like the config can actually be a bit simpler. The external pathGroup isn’t necessary.

      {
        pathGroups: [
          {
            pattern: '@/**',
            group: 'internal',
          },
        ],
        pathGroupsExcludedImportTypes: ['builtin', 'object'],
      },

gets the job done.

2reactions
johnlovencommented, Jun 9, 2021

You can also use an eslint setting in order to interpret specific path patterns as internal:

# .eslintrc.yml
settings:
  import/internal-regex: ^@/

https://github.com/benmosher/eslint-plugin-import/blob/master/README.md#importinternal-regex

Read more comments on GitHub >

github_iconTop Results From Across the Web

[order] pathGroup doesn't appear to work #2008 - GitHub
I am configuring pathGroups, but they do not appear to be working. No matter the group I set for the pattern, it always...
Read more >
Understanding My Bill | Pathgroup
A: PathGroup accepts check, money order and credit card payment (via mail or phone). Checks should be addressed to PathGroup and include your...
Read more >
Understanding My Bill - PathGroup
A: PathGroup accepts check, money order and credit card payment (via mail or phone). Checks should be addressed to PathGroup and include your...
Read more >
Pathgroup
PathGroup is privately held and physician centered, designed to work seamlessly with medical practices and provide direct consultation when needed.
Read more >
Specimen Collection Manual - Pathgroup
Check specimen container for expiration date prior to use. Order from MML Histology Department at (415) 209-6076 one week in advance of intended...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found