({ order })
| 1 | export default function RuleSortMethods({ order }) { |
| 2 | console.log("check method order"); |
| 3 | return { |
| 4 | PathItem: { |
| 5 | enter(pathItem, ctx) { |
| 6 | // default method sort order, can be changed with an "order" param in config |
| 7 | let methodOrder = ["post", "patch", "put", "get", "delete"]; |
| 8 | if (order) { |
| 9 | methodOrder = order; |
| 10 | } |
| 11 | |
| 12 | // Identify the methods that are present and put them in order |
| 13 | const methods = Object.getOwnPropertyNames(pathItem); |
| 14 | const expectedOrder = methodOrder.filter((item) => |
| 15 | methods.includes(item) |
| 16 | ); |
| 17 | |
| 18 | i = 0; |
| 19 | while (i < expectedOrder.length) { |
| 20 | // if this method is in the array, it must be in the expected order |
| 21 | if ( |
| 22 | expectedOrder.includes(methods[i]) && |
| 23 | methods[i] !== expectedOrder[i] |
| 24 | ) { |
| 25 | ctx.report({ |
| 26 | message: `Unexpected method order, expected ${expectedOrder[i]} but found ${methods[i]}`, |
| 27 | }); |
| 28 | } |
| 29 | i++; |
| 30 | } |
| 31 | }, |
| 32 | }, |
| 33 | }; |
| 34 | } |
nothing calls this directly
no outgoing calls
no test coverage detected