Skip to content

Commit

Permalink
fix(linter): handle workspace: protocol in general
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 11, 2025
1 parent 681e03a commit b64ab8b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
51 changes: 33 additions & 18 deletions packages/eslint-plugin/src/rules/dependency-checks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const rootPackageJson = {
dependencies: {
external1: '~16.1.2',
external2: '^5.2.0',
external3: '1.0.0',
external4: '1.0.0',
},
devDependencies: {
tslib: '^2.1.0',
Expand All @@ -53,6 +55,22 @@ const externalNodes: Record<string, ProjectGraphExternalNode> = {
version: '5.5.6',
},
},
'npm:external3': {
name: 'npm:external3',
type: 'npm',
data: {
packageName: 'external3',
version: '1.0.0',
},
},
'npm:external4': {
name: 'npm:external3',
type: 'npm',
data: {
packageName: 'external4',
version: '1.0.0',
},
},
'npm:random-external': {
name: 'npm:random-external',
type: 'npm',
Expand Down Expand Up @@ -1581,12 +1599,11 @@ describe('Dependency checks (eslint)', () => {
`);
});

it('should not report * and workspace:*', () => {
it('should not report *', () => {
const packageJson = {
name: '@mycompany/liba',
dependencies: {
external1: '*',
external2: 'workspace:*',
},
};

Expand Down Expand Up @@ -1616,33 +1633,24 @@ describe('Dependency checks (eslint)', () => {
},
externalNodes,
dependencies: {
liba: [
{ source: 'liba', target: 'npm:external1', type: 'static' },
{ source: 'liba', target: 'npm:external2', type: 'static' },
],
liba: [{ source: 'liba', target: 'npm:external1', type: 'static' }],
},
},
{
liba: [
createFile(`libs/liba/src/main.ts`, [
'npm:external1',
'npm:external2',
]),
createFile(`libs/liba/package.json`, [
'npm:external1',
'npm:external2',
]),
],
liba: [createFile(`libs/liba/src/main.ts`, ['npm:external1'])],
}
);
expect(failures.length).toEqual(0);
});
it('should not report workspace:^ and workspace:~', () => {

it('should not report workspace: protocol', () => {
const packageJson = {
name: '@mycompany/liba',
dependencies: {
external1: 'workspace:~',
external2: 'workspace:^',
external3: 'workspace:',
external4: 'workspace:../external4',
},
};

Expand Down Expand Up @@ -1675,6 +1683,8 @@ describe('Dependency checks (eslint)', () => {
liba: [
{ source: 'liba', target: 'npm:external1', type: 'static' },
{ source: 'liba', target: 'npm:external2', type: 'static' },
{ source: 'liba', target: 'npm:external3', type: 'static' },
{ source: 'liba', target: 'npm:external4', type: 'static' },
],
},
},
Expand All @@ -1683,17 +1693,22 @@ describe('Dependency checks (eslint)', () => {
createFile(`libs/liba/src/main.ts`, [
'npm:external1',
'npm:external2',
'npm:external3',
'npm:external4',
]),
createFile(`libs/liba/package.json`, [
'npm:external1',
'npm:external2',
'npm:external3',
'npm:external4',
]),
],
}
);
expect(failures.length).toEqual(0);
});
it('should not report catalog:', () => {

it('should not report catalog: protocol', () => {
const packageJson = {
name: '@mycompany/liba',
dependencies: {
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-plugin/src/rules/dependency-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ export default ESLintUtils.RuleCreator(
packageRange.startsWith('file:') ||
npmDependencies[packageName] === '*' ||
packageRange === '*' ||
packageRange === 'workspace:*' ||
packageRange === 'workspace:~' ||
packageRange === 'workspace:^' ||
packageRange.startsWith('workspace:') ||
/**
* Catalogs can be named, or left unnamed
* So just checking up until the : will catch both cases
Expand Down

0 comments on commit b64ab8b

Please sign in to comment.