Skip to content

Commit

Permalink
Fill in test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Oct 23, 2024
1 parent f787d23 commit ba6f191
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/rules/require-meta-schema-description.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { getStaticValue } = require('@eslint-community/eslint-utils');
const utils = require('../utils');

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -59,9 +60,12 @@ module.exports = {
let hadDescription = false;

for (const { key, value } of node.properties) {
if (key.computed) {
const staticKey =
key.type === 'Identifier' ? { value: key.name } : getStaticValue(key);
if (!staticKey?.value) {
continue;
}

switch (key.name ?? key.value) {
case 'description': {
hadDescription = true;
Expand Down
132 changes: 131 additions & 1 deletion tests/lib/rules/require-meta-schema-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,59 @@ const ruleTester = new RuleTester({

ruleTester.run('require-meta-schema-description', rule, {
valid: [
``,
`
module.exports = {};
`,
`
module.exports = {
create() {}
};
`,
`
module.exports = {
meta: {
schema: false,
},
create() {}
};
`,
`
module.exports = {
meta: {
schema: [false],
},
create() {}
};
`,
`
module.exports = {
meta: {
schema: [
{
description: 'Elements to allow.',
elements: { type: 'string' },
type: 'array',
},
],
},
};
`,
`
const descriptionKey = 'description';
module.exports = {
meta: {
schema: [
{
[descriptionKey]: 'Elements to allow.',
elements: { type: 'string' },
type: 'array',
},
],
},
};
`,
`
module.exports = {
meta: {
Expand Down Expand Up @@ -125,7 +178,84 @@ module.exports = {
meta: {
schema: [
{
['de' + 'scription']: 'Computed.',
[unknownKey]: 'Computed.',
elements: { type: 'string' },
type: 'array',
},
],
},
create() {}
};
`,
errors: [
{
column: 7,
endColumn: 8,
endLine: 9,
line: 5,
messageId: 'missingDescription',
},
],
},
{
code: `
module.exports = {
meta: {
schema: [
{
[unknownKey()]: 'Computed.',
elements: { type: 'string' },
type: 'array',
},
],
},
create() {}
};
`,
errors: [
{
column: 7,
endColumn: 8,
endLine: 9,
line: 5,
messageId: 'missingDescription',
},
],
},
{
code: `
const otherKey = 'other';
module.exports = {
meta: {
schema: [
{
[otherKey]: 'Computed.',
elements: { type: 'string' },
type: 'array',
},
],
},
create() {}
};
`,
errors: [
{
column: 7,
endColumn: 8,
endLine: 11,
line: 7,
messageId: 'missingDescription',
},
],
},
{
code: `
module.exports = {
meta: {
schema: [
{
['de' + 'scription']: 'Dynamic.',
elements: { type: 'string' },
type: 'array',
},
Expand Down

0 comments on commit ba6f191

Please sign in to comment.