Skip to content

Commit

Permalink
Merge pull request #112 from Dschungelabenteuer/fix-windows-paths
Browse files Browse the repository at this point in the history
fix(no-uninstalled-addons) Support Windows paths
  • Loading branch information
yannbf committed Jan 10, 2023
2 parents 8b7f603 + 2d8e6b8 commit 1397f4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/rules/no-uninstalled-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { readFileSync } from 'fs'
import dedent from 'ts-dedent'
import { resolve, relative } from 'path'
import { resolve, relative, sep } from 'path'

import { createStorybookRule } from '../utils/create-storybook-rule'
import { CategoryId } from '../utils/constants'
Expand Down Expand Up @@ -187,8 +187,8 @@ export = createStorybookRule({
(elem) => !!result.find((addon) => addon.name === elem.value)
)

const rootDir = process.cwd().split('/').pop()
const packageJsonPath = `${rootDir}/${relative(process.cwd(), packageJsonLocation)}`
const rootDir = process.cwd().split(sep).pop()
const packageJsonPath = `${rootDir}${sep}${relative(process.cwd(), packageJsonLocation)}`

elemsWithErrors.forEach((elem) => {
context.report({
Expand Down
21 changes: 11 additions & 10 deletions tests/lib/rules/no-uninstalled-addons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'

import rule from '../../../lib/rules/no-uninstalled-addons'
import ruleTester from '../../utils/rule-tester'
import { sep } from 'path';

jest.mock('fs', () => ({
...jest.requireActual('fs'),
Expand Down Expand Up @@ -137,7 +138,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/not-installed-addon',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -161,7 +162,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/not-installed-addon',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -184,7 +185,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/addon-esentials',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -205,7 +206,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/adon-essentials',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -228,15 +229,15 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: 'addon-withut-the-prefix',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
{
messageId: 'addonIsNotInstalled', // comes from the rule file
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/addon-esentials',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -259,15 +260,15 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: 'addon-withut-the-prefix',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
{
messageId: 'addonIsNotInstalled', // comes from the rule file
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/addon-esentials',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand All @@ -289,15 +290,15 @@ ruleTester.run('no-uninstalled-addons', rule, {
type: AST_NODE_TYPES.Literal,
data: {
addonName: 'addon-withut-the-prefix',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
{
messageId: 'addonIsNotInstalled', // comes from the rule file
type: AST_NODE_TYPES.Literal,
data: {
addonName: '@storybook/addon-esentials',
packageJsonPath: 'eslint-plugin-storybook/',
packageJsonPath: `eslint-plugin-storybook${sep}`,
},
},
],
Expand Down

0 comments on commit 1397f4f

Please sign in to comment.