Skip to content

Commit a1c0871

Browse files
committed
feat(lint): check descriptions of static members
1 parent 96fa6ed commit a1c0871

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

lint/linter/test-descriptions.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ const processApiData = (data, path, errors) => {
7979
`\`${featureName.replace('_permission', '')}\` permission`,
8080
errors,
8181
);
82+
} else if (featureName.endsWith('_static')) {
83+
const memberName = featureName.slice(0, -'_static'.length);
84+
const methodForm = `\`${memberName}()\` static method`;
85+
const propertyForm = `\`${memberName}\` static property`;
86+
const actual = data.description || '';
87+
if (!actual.startsWith(methodForm) && !actual.startsWith(propertyForm)) {
88+
errors.push({
89+
ruleName: 'static',
90+
path,
91+
actual,
92+
expected: methodForm,
93+
});
94+
}
8295
} else if (featureName == 'secure_context_required') {
8396
checkDescription(
8497
'secure context required',

lint/linter/test-descriptions.test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,86 @@ describe('test-descriptions', () => {
6969
);
7070
});
7171

72+
it('should check description for static method', () => {
73+
const path = 'api.Interface.create_static';
74+
/** @type {CompatStatement} */
75+
const data = {
76+
description: '',
77+
support: {},
78+
};
79+
80+
const errors = processData(data, 'api', path);
81+
assert.equal(errors.length, 1);
82+
assert.equal(
83+
/** @type {DescriptionError} */ (errors[0]).ruleName,
84+
'static',
85+
);
86+
});
87+
88+
it('should accept static method description', () => {
89+
const path = 'api.Interface.create_static';
90+
/** @type {CompatStatement} */
91+
const data = {
92+
description: '`create()` static method',
93+
support: {},
94+
};
95+
96+
const errors = processData(data, 'api', path);
97+
assert.equal(errors.length, 0);
98+
});
99+
100+
it('should accept static property description', () => {
101+
const path = 'api.Interface.maxActions_static';
102+
/** @type {CompatStatement} */
103+
const data = {
104+
description: '`maxActions` static property',
105+
support: {},
106+
};
107+
108+
const errors = processData(data, 'api', path);
109+
assert.equal(errors.length, 0);
110+
});
111+
112+
it('should accept static method description with trailing context', () => {
113+
const path = 'api.console.exception_static';
114+
/** @type {CompatStatement} */
115+
const data = {
116+
description: '`exception()` static method (an alias for `error()`)',
117+
support: {},
118+
};
119+
120+
const errors = processData(data, 'api', path);
121+
assert.equal(errors.length, 0);
122+
});
123+
124+
it('should reject static description with wrong name', () => {
125+
const path = 'api.Interface.only_static';
126+
/** @type {CompatStatement} */
127+
const data = {
128+
description: '`lowerBound()` static method',
129+
support: {},
130+
};
131+
132+
const errors = processData(data, 'api', path);
133+
assert.equal(errors.length, 1);
134+
assert.equal(
135+
/** @type {DescriptionError} */ (errors[0]).ruleName,
136+
'static',
137+
);
138+
});
139+
140+
it('should ignore _static_property suffix', () => {
141+
const path = 'api.Interface.disabledFeatures_static_property';
142+
/** @type {CompatStatement} */
143+
const data = {
144+
description: 'Supports `disabledFeatures` static property',
145+
support: {},
146+
};
147+
148+
const errors = processData(data, 'api', path);
149+
assert.equal(errors.length, 0);
150+
});
151+
72152
it('should check description for secure context required', () => {
73153
const path = 'api.Interface.secure_context_required';
74154
/** @type {CompatStatement} */

0 commit comments

Comments
 (0)