Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rulesets): propagate review suggestions
- Loading branch information
1 parent
4f83588
commit b33df5d
Showing
12 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...yncapi-channel-parameters-defined.test.ts → ...sts__/asyncapi-channel-parameters.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...asyncapi-server-variables-defined.test.ts → ...tests__/asyncapi-server-variables.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
packages/rulesets/src/asyncapi/functions/utils/__tests__/getMissingProps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getMissingProps } from '../getMissingProps'; | ||
|
||
describe('getMissingProps', () => { | ||
test('should return all props when object is empty', () => { | ||
const result = getMissingProps(['one', 'two', 'three'], {}); | ||
expect(result).toEqual(['one', 'two', 'three']); | ||
}); | ||
|
||
test('should return only missed props', () => { | ||
const result = getMissingProps(['one', 'two', 'three'], { one: {}, three: {} }); | ||
expect(result).toEqual(['two']); | ||
}); | ||
|
||
test('should return empty array when all props are defined', () => { | ||
const result = getMissingProps(['one', 'two', 'three'], { one: {}, two: {}, three: {} }); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/rulesets/src/asyncapi/functions/utils/__tests__/getRedundantProps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getRedundantProps } from '../getRedundantProps'; | ||
|
||
describe('getRedundantProps', () => { | ||
test('should return all redundant props when array is empty', () => { | ||
const result = getRedundantProps([], { one: {}, two: {}, three: {} }); | ||
expect(result).toEqual(['one', 'two', 'three']); | ||
}); | ||
|
||
test('should return only redundant props', () => { | ||
const result = getRedundantProps(['one', 'three'], { one: {}, two: {}, three: {} }); | ||
expect(result).toEqual(['two']); | ||
}); | ||
|
||
test('should return empty array when all props are defined', () => { | ||
const result = getRedundantProps(['one', 'two', 'three'], { one: {}, two: {}, three: {} }); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/rulesets/src/asyncapi/functions/utils/__tests__/parseUrlVariables.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { parseUrlVariables } from '../parseUrlVariables'; | ||
|
||
describe('parseUrlVariables', () => { | ||
test('should return all variables from string', () => { | ||
const result = parseUrlVariables('{stage}.some.{channel}'); | ||
expect(result).toEqual(['stage', 'channel']); | ||
}); | ||
|
||
test('should return empty array if no variable is defined', () => { | ||
const result = parseUrlVariables('stage.some.channel'); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/rulesets/src/asyncapi/functions/utils/getMissingProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function getMissingProps(arr: string[] = [], obj: Record<string, unknown> = {}): string[] { | ||
if (!Object.keys(obj).length) return arr; | ||
return arr.filter(val => { | ||
return !Object.prototype.hasOwnProperty.call(obj, val); | ||
}); | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/rulesets/src/asyncapi/functions/utils/getRedundantProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function getRedundantProps(arr: string[] = [], obj: Record<string, unknown> = {}): string[] { | ||
if (!arr.length) return Object.keys(obj); | ||
return Object.keys(obj).filter(val => { | ||
return !arr.includes(val); | ||
}); | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/rulesets/src/asyncapi/functions/utils/parseUrlVariables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function parseUrlVariables(str: string): string[] { | ||
if (typeof str !== 'string') return []; | ||
const variables = str.match(/{(.+?)}/g); | ||
if (!variables || variables.length === 0) return []; | ||
return variables.map(v => v.slice(1, -1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters