-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(specs): add out-of-line-one-of rule (and allOf and anyOf) APIC-418
(#512)
- Loading branch information
Showing
8 changed files
with
75 additions
and
52 deletions.
There are no files selected for viewing
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.
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,57 @@ | ||
import type { Rule } from 'eslint'; | ||
|
||
import { isPairWithKey } from '../utils'; | ||
|
||
export function createOutOfLineRule({ | ||
property, | ||
description = `${property} must be out of line, not nested inside properties`, | ||
messageId = `${property}NotOutOfLine`, | ||
message = `${property} must be out of line`, | ||
}: { | ||
property: string; | ||
description?: string; | ||
messageId?: string; | ||
message?: string; | ||
}): Rule.RuleModule { | ||
const rule: Rule.RuleModule = { | ||
meta: { | ||
docs: { | ||
description, | ||
}, | ||
messages: { | ||
[messageId]: message, | ||
}, | ||
}, | ||
create(context) { | ||
if (!context.parserServices.isYAML) { | ||
return {}; | ||
} | ||
|
||
return { | ||
YAMLPair(node): void { | ||
if (!isPairWithKey(node, property)) { | ||
return; | ||
} | ||
// parent is mapping, and parent is real parent that must be to the far left | ||
if (node.parent.parent.loc.start.column === 0) { | ||
return; | ||
} | ||
// accept anything in servers | ||
if ( | ||
isPairWithKey( | ||
node.parent.parent.parent.parent?.parent?.parent?.parent ?? null, | ||
'servers' | ||
) | ||
) { | ||
return; | ||
} | ||
context.report({ | ||
node: node.parent.parent as any, | ||
messageId, | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; | ||
return rule; | ||
} |
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
5 changes: 3 additions & 2 deletions
5
eslint/tests/outOfLineEnum.test.ts → eslint/tests/outOfLineRule.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