Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Jun 7, 2023
1 parent 2ab4d3e commit bcd73e7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
11 changes: 5 additions & 6 deletions __tests__/functions/json-validator.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { jsonValidator } from '../../src/functions/json-validator'
import {jsonValidator} from '../../src/functions/json-validator'
import * as core from '@actions/core'

const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => { })
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => { })
const errorMock = jest.spyOn(core, 'error').mockImplementation(() => { })
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
const errorMock = jest.spyOn(core, 'error').mockImplementation(() => {})

class Exclude {
isExcluded() {
Expand Down Expand Up @@ -188,7 +188,7 @@ test('fails to validate a yaml file with an incorrect schema when yaml_as_json i
errors: [
{
path: null,
message: 'must have required property \'foo\''
message: "must have required property 'foo'"
}
]
}
Expand All @@ -200,4 +200,3 @@ test('fails to validate a yaml file with an incorrect schema when yaml_as_json i
)
)
})

12 changes: 6 additions & 6 deletions __tests__/functions/yaml-validator.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { yamlValidator } from '../../src/functions/yaml-validator'
import {yamlValidator} from '../../src/functions/yaml-validator'
import * as core from '@actions/core'

const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => { })
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => { })
const errorMock = jest.spyOn(core, 'error').mockImplementation(() => { })
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
const errorMock = jest.spyOn(core, 'error').mockImplementation(() => {})

class Exclude {
isExcluded() {
Expand Down Expand Up @@ -179,7 +179,7 @@ test('skips all files when yaml_as_json is true', async () => {
expect(debugMock).toHaveBeenCalledWith(
'skipping yaml since it should be treated as json: ./__tests__/fixtures/yaml/valid/yaml1.yaml'
)
});
})

test('skips all files when yaml_as_json is true, even invalid ones', async () => {
process.env.INPUT_YAML_AS_JSON = true
Expand All @@ -198,4 +198,4 @@ test('skips all files when yaml_as_json is true, even invalid ones', async () =>
expect(debugMock).toHaveBeenCalledWith(
'skipping yaml since it should be treated as json: ./__tests__/fixtures/yaml/invalid/skip-bad.yaml'
)
});
})
24 changes: 12 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions src/functions/json-validator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import Ajv from 'ajv'
import { readFileSync } from 'fs'
import { globSync } from 'glob'
import { parse } from 'yaml'
import {readFileSync} from 'fs'
import {globSync} from 'glob'
import {parse} from 'yaml'

// setup the ajv instance
const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
Expand Down Expand Up @@ -57,20 +57,16 @@ export async function jsonValidator(exclude) {
violations: []
}

const yamlGlob = `${yamlExtension.replace('.', '')}, ${yamlExtensionShort.replace(
const yamlGlob = `${yamlExtension.replace(
'.',
''
)}`
)}, ${yamlExtensionShort.replace('.', '')}`

const glob = yamlAsJson
? `**/*{${jsonExtension},${yamlGlob}}`
: `**/*${jsonExtension}`

const glob = yamlAsJson ?
`**/*{${jsonExtension},${yamlGlob}}` :
`**/*${jsonExtension}`

const files = globSync(
glob,
{ cwd: baseDirSanitized }
)
const files = globSync(glob, {cwd: baseDirSanitized})
for (const file of files) {
// construct the full path to the file
const fullPath = `${baseDirSanitized}/${file}`
Expand Down
8 changes: 4 additions & 4 deletions src/functions/yaml-validator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import validateSchema from 'yaml-schema-validator'
import { readFileSync } from 'fs'
import { globSync } from 'glob'
import { parse } from 'yaml'
import {readFileSync} from 'fs'
import {globSync} from 'glob'
import {parse} from 'yaml'

// Helper function to validate all yaml files in the baseDir
export async function yamlValidator(exclude) {
Expand Down Expand Up @@ -35,7 +35,7 @@ export async function yamlValidator(exclude) {
'.',
''
)}}`,
{ cwd: baseDirSanitized }
{cwd: baseDirSanitized}
)
for (const file of files) {
// construct the full path to the file
Expand Down

0 comments on commit bcd73e7

Please sign in to comment.