@snyk/sweater-comb
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -1,2 +0,2 @@ | ||
const camelCaseRegex = /^([a-z]+([A-Z][a-z]+)*)$/; | ||
const snakeCaseRegex = /^([a-z]+(_[a-z]+)*)$/; | ||
@@ -8,7 +8,7 @@ module.exports = (targetVal, _opts, context) => { | ||
.filter((part) => part.length > 0 && !part.match(/^[{].*[}]/)) | ||
.filter((part) => !part.match(camelCaseRegex)); | ||
.filter((part) => !part.match(snakeCaseRegex)); | ||
if (invalid.length > 0) { | ||
return [ | ||
{ | ||
message: `Path elements were not camel case: ${invalid.join(', ')}`, | ||
message: `Path elements were not snake case: ${invalid.join(', ')}`, | ||
}, | ||
@@ -15,0 +15,0 @@ ]; |
{ | ||
"name": "@snyk/sweater-comb", | ||
"version": "v0.0.4+202108311421-a308741", | ||
"version": "v0.1.0+202109071117-1e74482", | ||
"description": "Snyk API linting rules", | ||
@@ -5,0 +5,0 @@ "main": "apinext.yaml", |
@@ -7,3 +7,3 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
beforeAll(async () => { | ||
rules = await loadRules(); | ||
rules = await loadRules('naming.yaml'); | ||
}); | ||
@@ -14,3 +14,5 @@ | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run( | ||
loadSpec('fixtures/componentCasing.fail.yaml'), | ||
); | ||
expect(result).not.toHaveLength(0); | ||
@@ -29,9 +31,13 @@ expect(result).toEqual( | ||
code: 'component-names-pascal-case', | ||
path: ['components', 'parameters', 'limit'], | ||
path: ['components', 'parameters', 'startingAfter'], | ||
}), | ||
expect.objectContaining({ | ||
code: 'component-names-pascal-case', | ||
path: ['components', 'parameters', 'starting_after'], | ||
path: ['components', 'schemas', 'hello-world'], | ||
}), | ||
expect.objectContaining({ | ||
code: 'component-names-pascal-case', | ||
path: ['components', 'schemas', 'JSON-API'], | ||
}), | ||
expect.objectContaining({ | ||
code: 'component-response-names', | ||
@@ -38,0 +44,0 @@ path: ['components', 'responses', 'bad_things'], |
@@ -7,3 +7,3 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
beforeAll(async () => { | ||
rules = await loadRules(); | ||
rules = await loadRules('jsonapi.yaml'); | ||
}); | ||
@@ -14,3 +14,5 @@ | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run( | ||
loadSpec('fixtures/jsonapiSchema.fail.yaml'), | ||
); | ||
expect(result).not.toHaveLength(0); | ||
@@ -17,0 +19,0 @@ expect(result).toEqual( |
@@ -7,17 +7,25 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
beforeAll(async () => { | ||
rules = await loadRules(); | ||
rules = await loadRules('naming.yaml'); | ||
}); | ||
it('fails on camel case violation', async () => { | ||
it('fails on snake case violation', async () => { | ||
const spectral = new Spectral(); | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
expect(result).not.toHaveLength(0); | ||
const result = await spectral.run(loadSpec('fixtures/paramCasing.fail.yaml')); | ||
expect(result).not.toHaveLength(3); | ||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
code: 'parameter-names-camel-case', | ||
code: 'parameter-names-snake-case', | ||
path: ['components', 'parameters', 'EndingBefore', 'name'], | ||
}), | ||
expect.objectContaining({ | ||
code: 'parameter-names-snake-case', | ||
path: ['components', 'parameters', 'StartingAfter', 'name'], | ||
}), | ||
expect.objectContaining({ | ||
code: 'parameter-names-snake-case', | ||
path: [ | ||
'paths', | ||
'/examples/hello_world/HelloWorld/hello-world/{hello-id}', | ||
'/examples/hello_world/{hello-id}', | ||
'get', | ||
@@ -24,0 +32,0 @@ 'parameters', |
@@ -7,9 +7,9 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
beforeAll(async () => { | ||
rules = await loadRules(); | ||
rules = await loadRules('naming.yaml'); | ||
}); | ||
it('fails on camel case violation', async () => { | ||
it('fails on snake case violation', async () => { | ||
const spectral = new Spectral(); | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run(loadSpec('fixtures/pathCasing.fail.yaml')); | ||
expect(result).not.toHaveLength(0); | ||
@@ -19,7 +19,23 @@ expect(result).toEqual( | ||
expect.objectContaining({ | ||
code: 'paths-camel-case', | ||
message: `Path elements were not camel case: hello_world, HelloWorld, hello-world`, | ||
code: 'paths-snake-case', | ||
message: `Path elements were not snake case: HelloWorld`, | ||
}), | ||
expect.objectContaining({ | ||
code: 'paths-snake-case', | ||
message: `Path elements were not snake case: helloWorld`, | ||
}), | ||
expect.objectContaining({ | ||
code: 'paths-snake-case', | ||
message: `Path elements were not snake case: hello-world`, | ||
}), | ||
expect.objectContaining({ | ||
code: 'paths-snake-case', | ||
message: `Path elements were not snake case: HELLO-WORLD`, | ||
}), | ||
expect.objectContaining({ | ||
code: 'paths-snake-case', | ||
message: `Path elements were not snake case: HELLO_WORLD`, | ||
}), | ||
]), | ||
); | ||
}); |
@@ -13,4 +13,4 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.yaml')); | ||
const result = await spectral.run(loadSpec('fixtures/valid.yaml')); | ||
expect(result).toHaveLength(0); | ||
}); |
@@ -7,3 +7,3 @@ const { Spectral } = require('@stoplight/spectral-core'); | ||
beforeAll(async () => { | ||
rules = await loadRules(); | ||
rules = await loadRules('versioning.yaml'); | ||
}); | ||
@@ -14,3 +14,3 @@ | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run(loadSpec('fixtures/version.fail.yaml')); | ||
expect(result).not.toHaveLength(0); | ||
@@ -81,3 +81,3 @@ expect(result).toEqual( | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run(loadSpec('fixtures/version.fail.yaml')); | ||
expect(result).not.toHaveLength(0); | ||
@@ -97,3 +97,3 @@ expect(result).toEqual( | ||
spectral.setRuleset(rules); | ||
const result = await spectral.run(loadSpec('hello-world.fail.yaml')); | ||
const result = await spectral.run(loadSpec('fixtures/version.fail.yaml')); | ||
expect(result).not.toHaveLength(0); | ||
@@ -100,0 +100,0 @@ expect(result).toEqual( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
56975
35
414