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

fix: Allow to import packages from devDependencies within config files #580

Merged
merged 1 commit into from Jul 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions parts/base.js
Expand Up @@ -93,4 +93,13 @@ module.exports = {
ignoreGlobals: true,
}],
},
overrides: [
{
// Allow "unpublished" == devDependencies to be imported in config files
files: ['*.config.*', 'cypress/**/*', 'tests/**/*', '__tests__/**/*', '__mocks__/**/*'],
rules: {
'n/no-unpublished-import': 'off',
},
},
],
}
32 changes: 16 additions & 16 deletions tests/setup-jest.ts
@@ -1,12 +1,12 @@
import { ESLint, Linter } from "eslint"
import { ESLint, Linter } from 'eslint'

/**
* Add some custom matchers for ESLint to jest
*/
expect.extend({
toPass: assertLintingPassed,
toHaveIssueCount: assertHavingNIssues,
toHaveIssue: assertHavingIssue
toHaveIssue: assertHavingIssue,
})

/**
Expand All @@ -24,8 +24,8 @@ function hasNoIssues(received: ESLint.LintResult) {
/**
* Check if linting of multiple fils
*
* @param received
* @returns {}
* @param received
* @return {}
*/
function assertLintingPassed(received: ESLint.LintResult | ESLint.LintResult[]) {
// allow single ESLintResult
Expand All @@ -36,7 +36,7 @@ function assertLintingPassed(received: ESLint.LintResult | ESLint.LintResult[])
const errors = [] as {file: string, errors: Linter.LintMessage[]}[]
const pass = received.every((result) => {
// save issues
errors.push({file: result.filePath, errors: result.messages})
errors.push({ file: result.filePath, errors: result.messages })
return hasNoIssues(result)
})

Expand All @@ -46,20 +46,20 @@ function assertLintingPassed(received: ESLint.LintResult | ESLint.LintResult[])
if (pass) {
return 'Expected file to not pass eslint, but got no issues'
} else {
const errorMessages = errors.map((m) =>
`file: ${m.file}\n` + m.errors.map((e) => 'line: ' + e.line + ': ' + (e.ruleId || e.message))
const errorMessages = errors.map((m) =>
`file: ${m.file}\n` + m.errors.map((e) => 'line: ' + e.line + ': ' + (e.ruleId || e.message)),
)
return 'Expected file to pass eslint, got issues:\n' + errorMessages.join('\n')
}
}
},
}
}

/**
* Count the total amount of issues
*
* @param received lint result
* @returns total amount of issues
* @return total amount of issues
*/
function countIssues(received: ESLint.LintResult) {
return received.errorCount + received.warningCount
Expand All @@ -70,7 +70,7 @@ function countIssues(received: ESLint.LintResult) {
*
* @param received the lint result
* @param expected number of expected issues
* @returns jest matcher result
* @return jest matcher result
*/
function assertHavingNIssues(received: ESLint.LintResult | ESLint.LintResult[], expected: number) {
if (!(typeof expected === 'number')) throw new Error('Expected a number as expected value')
Expand All @@ -84,7 +84,7 @@ function assertHavingNIssues(received: ESLint.LintResult | ESLint.LintResult[],

return {
pass,
message: () => pass ? `Expected not to find exactly ${expected} issues.` : `Expected ${expected} issues, found ${issues}`
message: () => pass ? `Expected not to find exactly ${expected} issues.` : `Expected ${expected} issues, found ${issues}`,
}
}

Expand All @@ -93,7 +93,7 @@ function assertHavingNIssues(received: ESLint.LintResult | ESLint.LintResult[],
*
* @param received the lint result
* @param issue the expected issue
* @returns jest matcher result
* @return jest matcher result
*/
function assertHavingIssue(received: ESLint.LintResult | ESLint.LintResult[], issue: string | {ruleId: string, line?: number}) {
if (!Array.isArray(received)) {
Expand All @@ -104,7 +104,7 @@ function assertHavingIssue(received: ESLint.LintResult | ESLint.LintResult[], is
if (assertLintingPassed(received).pass) {
return {
pass: false,
message: () => 'Expected issue, but no linting issues found.'
message: () => 'Expected issue, but no linting issues found.',
}
}

Expand All @@ -115,14 +115,14 @@ function assertHavingIssue(received: ESLint.LintResult | ESLint.LintResult[], is
if (message.ruleId !== name) return false
// if line is requested ignore not matching ones
if (typeof issue === 'object' && issue.line !== undefined && issue.line !== message.line) return false
// otherwise matched
// otherwise matched
return true
})
});
})

const onLine = typeof issue === 'string' ? '' : ` on line ${issue.line}`
return {
pass: result,
message: () => result ? `Unexpected error '${name}'${onLine} found.` : `Expected error '${name}'${onLine} not found.`
message: () => result ? `Unexpected error '${name}'${onLine} found.` : `Expected error '${name}'${onLine} not found.`,
}
}