Skip to content

Commit

Permalink
Merge pull request #12 from quesabe/update-deps-danger.11
Browse files Browse the repository at this point in the history
updated danger, eslint, ramda typings, some typos
  • Loading branch information
quesabe authored Mar 27, 2022
2 parents e213cef + de45c9c commit a6da4f6
Show file tree
Hide file tree
Showing 13 changed files with 7,445 additions and 9,161 deletions.
16,451 changes: 7,363 additions & 9,088 deletions package-lock.json

Large diffs are not rendered by default.

41 changes: 22 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,34 @@
},
"license": "ISC",
"devDependencies": {
"@babel/parser": "7.13.15",
"@babel/preset-env": "7.13.10",
"@babel/preset-typescript": "7.13.0",
"@ottofeller/eslint-config-ottofeller": "0.8.2",
"@rollup/plugin-commonjs": "17.1.0",
"@rollup/plugin-node-resolve": "11.2.0",
"@rollup/plugin-typescript": "8.2.0",
"@types/jest": "26.0.21",
"babel-jest": "26.6.3",
"@babel/preset-env": "7.16.11",
"@babel/preset-typescript": "7.16.7",
"@ottofeller/eslint-config-ottofeller": "0.15.6",
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-node-resolve": "13.1.3",
"@rollup/plugin-typescript": "8.3.0",
"@types/jest": "27.4.1",
"babel-jest": "27.5.1",
"babel-plugin-module-resolver": "4.1.0",
"babel-preset-node": "5.1.1",
"eslint": "7.22.0",
"rollup": "2.58.3",
"ts-jest": "26.5.4",
"tslib": "2.1.0",
"typescript": "4.2.3"
"eslint": "8.9.0",
"jest": "27.5.1",
"rollup": "2.68.0",
"ts-jest": "27.1.3",
"tslib": "2.3.1",
"typescript": "4.5.5"
},
"dependencies": {
"@types/ramda": "0.27.39",
"danger": "10.6.4",
"jest": "26.6.3",
"ramda": "0.27.1"
"@babel/parser": "7.17.3",
"@types/ramda": "0.27.64",
"danger": "11.0.2",
"ramda": "0.28.0"
},
"peerDependencies": {
"danger": ">=11.0.2"
},
"eslintConfig": {
"extends": "@ottofeller/eslint-config-ottofeller/node"
"extends": "@ottofeller/eslint-config-ottofeller/eslint.node"
},
"jest": {
"coveragePathIgnorePatterns": [
Expand Down
4 changes: 2 additions & 2 deletions src/bump-package-version/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('The rule that requires bumping the version in package.json in every pu
git: {
fileMatch: (path: string) => ({edited: path.startsWith(includePaths[1])}),

// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- exact signature required for a mock
JSONDiffForFile: async (filename: string): Promise<JSONDiff> => ({
version: {added: [], after: '0.0.1', before: '0.0.1', removed: []},
}),
Expand All @@ -36,7 +36,7 @@ describe('The rule that requires bumping the version in package.json in every pu
git: {
fileMatch: (path: string) => ({edited: path.startsWith(includePaths[1])}),

// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- exact signature required for a mock
JSONDiffForFile: async (filename: string): Promise<JSONDiff> => ({
version: {added: [], after: '0.0.1', before: '0.2.0', removed: []},
}),
Expand Down
12 changes: 6 additions & 6 deletions src/bump-package-version/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as R from 'ramda'
import {DangerDSLType} from 'danger'

/**
* Checks all @includePaths and in case of presence of edited files
* Checks all @includePaths and in case of presence of edited files
* requires version in `package.json` to be updated.
* Parameter @restrictToBranches defines branches to run the check for.
*/
Expand All @@ -14,18 +15,17 @@ export const bumpPackageVersion = async (params: {
if(!params.restrictToBranches.includes(params.danger.github.pr.base.ref)) {
return
}

// eslint-disable-next-line fp/no-loops
for(const includePath of params.includePaths) {

R.forEach(async includePath => {
// If there are no edits in the includePath the version should not be bumped
if(!params.danger.git.fileMatch(`${includePath}/**/*`).edited) {
continue
return
}

const packageJson = await params.danger.git.JSONDiffForFile(`${includePath}/package.json`)

if(!packageJson || !packageJson.version || packageJson.version.after === packageJson.version.before) {
params.fail(`The version in package.json must be updated in ${includePath}`)
}
}
}, params.includePaths)
}
12 changes: 6 additions & 6 deletions src/common-code-dir/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable max-lines */
/* eslint-disable max-lines -- too many tests, need those extra lines */
import * as fs from 'fs'
import * as R from 'ramda'
import {commonCodeDir} from '../index'
Expand All @@ -11,13 +11,13 @@ describe('Common code dir rule', () => {

// @ts-ignore
fs.readdirSync.mockImplementation((path: string) => {
/*
/* Folder structure
src/
common/
helpers/
some-helper/
index.tsx
index.tsx
ComponentA/
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('Common code dir rule', () => {
danger: {git: {
fileMatch: () => ({edited: true, getKeyedPaths: () => ({edited: ['src/ComponentA/index.tsx']})}),
}} as DangerDSLType,

fail : failMock,
includePaths: ['src/'],
})
Expand Down Expand Up @@ -229,15 +229,15 @@ describe('Common code dir rule', () => {
danger: {git: {
fileMatch: () => ({edited: true, getKeyedPaths: () => ({edited: ['src/ComponentA/index.tsx']})}),
}} as DangerDSLType,

fail : failMock,
includePaths: ['src/'],
})

expect(failMock).not.toHaveBeenCalled()
})

it('doesn\'t throw a fail in case multiple imports from node_mmodules', () => {
it('doesn\'t throw a fail in case multiple imports from node_modules', () => {
const failMock = jest.fn()

// @ts-ignore
Expand Down
13 changes: 6 additions & 7 deletions src/common-code-dir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const readdirNested = (params: {allFoundFiles: Array<string>, path: string}): Ar
* - Construct plain array of all imports
* - If an import paths counts more than once and has no "/common/" string included, throw a fail().
* @param danger Dnager instance
* @param danger Danger instance
* @param fail Danger fail function
* @param includePaths paths to include
* @param excludePaths paths to exclude
* @param baseImportPath base path for imports resolution
* @param extraCommonDirNames extra folders for common code
* @param babelPlugins babel plugins used in code parsing
* @param babelPlugins babel plugins used in code parsing
* (`jsx` and `typescript` are included by default)
*/
export const commonCodeDir = (params: {
Expand All @@ -56,7 +56,7 @@ export const commonCodeDir = (params: {
},

R.toPairs(R.compose<
Array<string>,
Array<Array<string>>,
Array<Array<string>>,
Array<string>,
Array<Array<string>>,
Expand All @@ -83,7 +83,7 @@ export const commonCodeDir = (params: {
R.flatten,

R.map(innerPath => R.compose<
string,
Array<string>,
Array<babelTypes.Statement>,
Array<babelTypes.Statement>,
Array<string | undefined>,
Expand Down Expand Up @@ -116,7 +116,7 @@ export const commonCodeDir = (params: {
).program.body
} catch(error) {
if(error instanceof Error) {
params.fail(`${error.name} occured while parsing file:\n${error.message}\n${filePath}`)
params.fail(`${error.name} ocurred while parsing file:\n${error.message}\n${filePath}`)
}else{
params.fail(`Error happened: ${error}`)
}
Expand All @@ -125,14 +125,13 @@ export const commonCodeDir = (params: {
return []
},
)(innerPath)),

R.flatten,

// Find all js/jsx/ts/tsx files (including nested ones) in a dir
// Exclude unit tests, their imports should not be considered as common
// Exclude node_modules folders
// Exclude path that include excludePath string
R.map(includePath => R.filter(
R.map<string, Array<string>>(includePath => R.filter(
innerPath => !R.isEmpty(R.match(/(js|jsx|ts|tsx)$/i, innerPath))
&& R.isEmpty(R.match(/__tests__/i, innerPath))
&& R.isEmpty(R.match(/\/node_modules\//i, innerPath))
Expand Down
8 changes: 4 additions & 4 deletions src/hasura/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Hasura rules', () => {
]}),
}),
}} as DangerDSLType,

hasuraMigrationsPath: 'hasura/migrations',
maxMigrationsLimit : 10,
warn : warnMock,
Expand All @@ -37,11 +37,11 @@ describe('Hasura rules', () => {
getKeyedPaths: () => ({edited: [
'src/some-file/index.tsx', 'hasura/migrations/1/up', 'hasura/migrations/1/down', 'hasura/migrations/2/up',
'hasura/migrations/2/down', 'hasura/migrations/3/up', 'hasura/migrations/3/down',
'hasura/migrations/4/up', 'hasura/migrations/4/down',
'hasura/migrations/4/up', 'hasura/migrations/4/down',
]}),
}),
}} as DangerDSLType,

hasuraMigrationsPath: 'hasura/migrations',
maxMigrationsLimit : 10,
warn : warnMock,
Expand All @@ -52,7 +52,7 @@ describe('Hasura rules', () => {
})

describe('Codegen missing', () => {
it('throws a warn if there are Hasura migraions updates but no schema and codegen generated types updates', () => {
it('throws a warn if there are Hasura migrations updates but no schema and codegen generated types updates', () => {
const warnMock = jest.fn()
const codegenFileExtension = 'generated.ts'
const codegenPaths = ['generated', 'graphql']
Expand Down
8 changes: 4 additions & 4 deletions src/hasura/codegen-missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {DangerDSLType} from 'danger'

/**
* Searches for Hasura migrations in edited files.
* If present, warns in ccase of no changes in codegen files and `schema.json`.
*
* @param danger Dnager instance
* If present, warns in case of no changes in codegen files and `schema.json`.
*
* @param danger Danger instance
* @param warn Danger warn function
* @param hasuraMigrationsPath paths to Hasura migrations
* @param codegenPaths paths to codegen files
Expand All @@ -27,7 +27,7 @@ export const codegenMissing = (params: {
return
}

const codegenEditedFiles = R.compose<Array<string>, Array<Array<string>>, Array<string>>(
const codegenEditedFiles = R.compose<Array<Array<string>>, Array<Array<string>>, Array<string>>(
R.flatten,

R.map(path => {
Expand Down
4 changes: 2 additions & 2 deletions src/hasura/squash-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {DangerDSLType} from 'danger'
/**
* Searches for Hasura migrations in edited files.
* If present, warns if the quantity of migration files to be within specified limit.
*
* @param danger Dnager instance
*
* @param danger Danger instance
* @param warn Danger warn function
* @param hasuraMigrationsPath paths to Hasura migrations
* @param maxMigrationsLimit maximum allowed migration files quantity
Expand Down
8 changes: 4 additions & 4 deletions src/nextjs/disallow-extension-in-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as R from 'ramda'
import {DangerDSLType} from 'danger'

/**
* Disallow a file extension in the selected dirs
* Disallow a file extension in the selected dirs
* and provides a required extension for the files.
*
* @param danger Dnager instance
*
* @param danger Danger instance
* @param fail Danger fail function
* @param excludePaths paths to exclude
* @param includePaths paths to include
* @param extension not allowed estension
* @param extension not allowed extension
* @param requireExtension required extension
*/
export const disallowExtensionInDirs = (params: {
Expand Down
20 changes: 10 additions & 10 deletions src/react/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable max-lines */
/* eslint-disable max-lines -- too many tests, need those extra lines */
import * as fs from 'fs'
import {componentHasTests, dirNameRestrictions} from '../index'
import {DangerDSLType} from 'danger'
Expand All @@ -18,31 +18,31 @@ describe('React rules', () => {
it(`does not check "${dirName}" folders`, () => {
const componentFilePath = 'src/another/Component/index.tsx'
const testFilePath = `src/another/Component/${dirName}/index.tsx`

// @ts-ignore
fs.readFileSync.mockImplementation((path: string) => {
if(path === testFilePath || path === componentFilePath) {
return validReactComponent
}
})

dirNameRestrictions({
danger: {git: {
created_files: [] as Array<string>,

fileMatch: (file: string) => ({
getKeyedPaths: () => ({created: [''], edited: [file]}),
}),

modified_files: [testFilePath],
}} as DangerDSLType,

fail : failMock,
includePaths: ['src'],
})

expect(failMock).not.toHaveBeenCalled()

// Once per each path component, but not for "dirName"
expect(fs.readFileSync).toHaveBeenCalledTimes(3)
})
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('React rules', () => {
describe('Check for test coverage', () => {
const fsMock = (path: string) => {
switch(path){
case'src/ComponentWithInvalidTest/__tests__/index.tsx':
case'src/ComponentWithInvalidTest/__tests__/index.tsx':
return 'import {SomeOtherStuff} from \'../index\''
case'src/ComponentWithInvalidTest/index.tsx':
return 'const ComponentWithInvalidTest = memo(function NewComponent() { return null })'
Expand All @@ -318,7 +318,7 @@ describe('React rules', () => {
return validReactComponent

default: {
let error: Error & { code?: string } = new Error()
let error: Error & {code?: string} = new Error()
error.code = 'ENOENT'
throw error
}}
Expand Down
Loading

0 comments on commit a6da4f6

Please sign in to comment.