@wmfs/statelint
Advanced tools
Comparing version
@@ -0,1 +1,3 @@ | ||
const JSONPathChecker = require('@wmfs/j2119/lib/j2119/json_path_checker') | ||
class StateNode { | ||
@@ -116,3 +118,7 @@ constructor () { | ||
for (const name of Object.keys(node.States)) { | ||
for (const [name, child] of Object.entries(node.States)) { | ||
if (isObject(child) && child.Parameters) { | ||
this.probeParameters(child, `${path}.${name}`, problems) | ||
} | ||
if (this.allStateNames.has(name)) { | ||
@@ -134,3 +140,21 @@ problems.push(`State "${name}", defined at ${path}.States, ` + | ||
) | ||
} | ||
} // checkForOrphanStates | ||
probeParameters (node, path, problems) { | ||
if (isArray(node)) { | ||
for (const [index, value] of node.entries()) { | ||
this.probeParameters(value, `${path}[${index}]`, problems) | ||
} // for ... | ||
} else if (isObject(node)) { | ||
for (const [name, value] of Object.entries(node)) { | ||
if (name.endsWith('.$')) { | ||
if (!isString(value) || !JSONPathChecker.isPath(value)) { | ||
problems.push(`Field "${name}" of Parameters at "${path}" is not a JSONPath`) | ||
} | ||
} else { | ||
this.probeParameters(value, `${path}.${name}`, problems) | ||
} // if (name.endsWith('.$')) | ||
} // for ... | ||
} // if (isArray(node)) ... | ||
} // probeParameters | ||
} // class StateNode | ||
@@ -137,0 +161,0 @@ |
{ | ||
"name": "@wmfs/statelint", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "Validator for Amazon States Language JSON files.", | ||
@@ -16,3 +16,3 @@ "author": "West Midlands Fire Service", | ||
"type": "git", | ||
"url": "git+https://github.com/wmfs/statelint.git" | ||
"url": "https://github.com/wmfs/statelint.git" | ||
}, | ||
@@ -27,3 +27,3 @@ "bugs": { | ||
"dependencies": { | ||
"@wmfs/j2119": "1.6.3", | ||
"@wmfs/j2119": "1.6.4", | ||
"cli": "1.0.1", | ||
@@ -60,15 +60,3 @@ "n-readlines": "1.0.0" | ||
"access": "public" | ||
}, | ||
"release": { | ||
"analyzeCommits": { | ||
"preset": "angular", | ||
"releaseRules": [ | ||
{ | ||
"type": "build", | ||
"scope": "deps", | ||
"release": "minor" | ||
} | ||
] | ||
} | ||
} | ||
} |
@@ -32,2 +32,59 @@ /* eslint-env mocha */ | ||
describe('Parameters only valid on Pass, Task, and Parallel', () => { | ||
verify( | ||
'Pass With Parameters', | ||
require('./fixtures/pass-with-parameters'), | ||
0 | ||
) | ||
verify( | ||
'Task With Parameters', | ||
require('./fixtures/task-with-parameters'), | ||
0 | ||
) | ||
verify( | ||
'Parallel With Parameters', | ||
require('./fixtures/parallel-with-parameters'), | ||
0 | ||
) | ||
}) | ||
describe('Parameters not valid on all other state types', () => { | ||
verify( | ||
'Choice With Parameters', | ||
require('./fixtures/choice-with-parameters'), | ||
1, | ||
'"Parameters' | ||
) | ||
verify( | ||
'Wait With Parameters', | ||
require('./fixtures/wait-with-parameters'), | ||
1, | ||
'"Parameters' | ||
) | ||
verify( | ||
'Succeed With Parameters', | ||
require('./fixtures/succeed-with-parameters'), | ||
1, | ||
'"Parameters' | ||
) | ||
verify( | ||
'Fail With Parameters', | ||
require('./fixtures/fail-with-parameters'), | ||
1, | ||
'"Parameters' | ||
) | ||
}) | ||
describe('Parameter paths', () => { | ||
verify( | ||
'reject non-Path constructs in Parameter fields ending in ".$"', | ||
require('./fixtures/parameter-path-problems'), | ||
4, | ||
'bad1', | ||
'bad2', | ||
'bad3', | ||
'bad4' | ||
) | ||
}) | ||
describe('ResultPath only valid on Pass, Task, Parallel', () => { | ||
@@ -232,3 +289,3 @@ verify( | ||
function verify (label, json, count, msg) { | ||
function verify (label, json, count, ...msg) { | ||
it(label, () => { | ||
@@ -241,6 +298,6 @@ const linter = stateLint() | ||
expect(problems.length).to.eql(count) | ||
if (msg) { | ||
expect(problems[0]).to.include(msg) | ||
for (let i = 0; i !== msg.length; ++i) { | ||
expect(problems[i]).to.include(msg[i]) | ||
} | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
45250
14.34%38
35.71%1097
26.09%+ Added
+ Added
- Removed
- Removed
Updated