-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathuse-string-literal-names.ts
43 lines (38 loc) · 1.21 KB
/
use-string-literal-names.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @fileoverview Use string literals to override a story name
* @author Charles Gruenais
*/
import { createStorybookRule } from '../utils/create-storybook-rule'
import { CategoryId } from '../utils/constants'
import { isLiteral } from '../utils/ast'
import { extractStories } from '../utils/stories'
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const messageId = 'useStringLiteralName' as const
export = createStorybookRule({
name: 'use-string-literal-names',
defaultOptions: [],
meta: {
type: 'problem',
docs: {
description: 'Use string literals to override a story name',
categories: [CategoryId.RECOMMENDED],
recommended: 'error',
},
messages: {
[messageId]: 'Story names can only be overridden by string literals',
},
schema: [],
},
create(context) {
return extractStories(context, (output) => {
const properties = output.getProperties(['name', 'storyName'])
properties.forEach(({ valueNode: node }) => {
if (!isLiteral(node)) {
context.report({ node, messageId })
}
})
})
},
})