[eslint] Remove unused `static-tag-must-be-static-property` rule. Bug: 370734442 Change-Id: I88925be37d6217f01764c02a6119ac6b30acb2a8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6126882 Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Nikolay Vitkov <nvitkov@chromium.org> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
diff --git a/scripts/eslint_rules/lib/static-tag-must-be-static-property.js b/scripts/eslint_rules/lib/static-tag-must-be-static-property.js deleted file mode 100644 index c125a31..0000000 --- a/scripts/eslint_rules/lib/static-tag-must-be-static-property.js +++ /dev/null
@@ -1,71 +0,0 @@ -// Copyright 2021 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -'use strict'; - -const {isLitHtmlTemplateCall} = require('./utils.js'); - -module.exports = { - meta: { - type: 'problem', - - docs: { - description: 'Check for <devtools-* in Lit templates instead of tag names.', - category: 'Possible Errors', - }, - fixable: 'code', - messages: { - invalidStaticProperty: - 'Found an invalid static tag interpolated value. Static tags should be named "litTagName" and be accessed from the class they are defined on: ${Foo.litTagName}.' - }, - schema: [] // no options - }, - create: function(context) { - function interpolatedStaticTagUsesLitTagName(interpolatedPart) { - // This means it's not of the form ${Foo.someMember} and is instead ${foo} - if (interpolatedPart.type !== 'MemberExpression') { - context.report({node: interpolatedPart, messageId: 'invalidStaticProperty'}); - return; - } - - // If we're inspecting `Foo.litTagName`, `Foo` === objectName, and - // `litTagName` === staticPropertyName. - const objectName = interpolatedPart.object.name; - const staticPropertyName = interpolatedPart.property.name; - - // Ensure that the object starts with a capital (best we can do to ensure - // it's a class), and make sure the static property is called - // `litTagName`. - if (!/[A-Z]/.test(objectName) || staticPropertyName !== 'litTagName') { - context.report({node: interpolatedPart, messageId: 'invalidStaticProperty'}); - } - } - - return { - TaggedTemplateExpression(node) { - if (!isLitHtmlTemplateCall(node)) { - return; - } - - const literalTemplateParts = node.quasi.quasis; - const templateExpressionParts = node.quasi.expressions; - - /** - * Look for a template part which ends with `<` (opening tag) or `</` - * (closing tag), followed by one that starts with `>`. Then check the - * expression that splits those parts. - */ - literalTemplateParts.forEach((part, partIndex) => { - const nextPart = literalTemplateParts[partIndex + 1]; - if (part.value.raw.endsWith('<') && nextPart && nextPart.value.raw.startsWith('>')) { - // Opening tag - interpolatedStaticTagUsesLitTagName(templateExpressionParts[partIndex]); - } else if (part.value.raw.endsWith('</') && nextPart && nextPart.value.raw.startsWith('>')) { - // Closing tag - interpolatedStaticTagUsesLitTagName(templateExpressionParts[partIndex]); - } - }); - }, - }; - } -};
diff --git a/scripts/eslint_rules/tests/static-tag-must-be-static-property.test.js b/scripts/eslint_rules/tests/static-tag-must-be-static-property.test.js deleted file mode 100644 index a47d591..0000000 --- a/scripts/eslint_rules/tests/static-tag-must-be-static-property.test.js +++ /dev/null
@@ -1,93 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -'use strict'; - -const rule = require('../lib/static-tag-must-be-static-property.js'); -const ruleTester = new (require('eslint').RuleTester)({ - parserOptions: {ecmaVersion: 9, sourceType: 'module'}, - parser: require.resolve('@typescript-eslint/parser'), -}); - -ruleTester.run('static-tag-must-be-static-property', rule, { - valid: [ - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${Foo.litTagName}></\${Foo.litTagName}>\` - `, - filename: 'front_end/components/test.ts', - }, - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${Foo.litTagName}><p>\${someValue}</p></\${Foo.litTagName}>\` - `, - filename: 'front_end/components/test.ts', - }, - { - code: `notLitHtmlCall\`<\${anyThingGoes}><p>\${someValue}</p></\${Foo.litTagName}>\` - `, - filename: 'front_end/components/test.ts', - }, - ], - invalid: [ - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${Foo}></\${Foo}>\` - `, - filename: 'front_end/components/test.ts', - // Two errors: one for opening, one for closing tag - errors: [ - {messageId: 'invalidStaticProperty', column: 23, line: 5}, - {messageId: 'invalidStaticProperty', column: 32, line: 5} - ] - }, - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${Foo.litTagName}></\${Foo}>\` - `, - filename: 'front_end/components/test.ts', - // One error: the closing tag is invalid. - errors: [{messageId: 'invalidStaticProperty', column: 43, line: 5}] - }, - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${Foo.invalidTagName}></\${Foo.otherInvalidName}>\` - `, - filename: 'front_end/components/test.ts', - // Two errors: both use the wrong static property - errors: [ - {messageId: 'invalidStaticProperty', column: 23, line: 5}, - {messageId: 'invalidStaticProperty', column: 47, line: 5} - ] - }, - { - code: `class Foo extends HTMLElement { - static readonly litTagName = LitHtml.literal\`foo-bar\`; - }; - - LitHtml.html\`<\${foo.litTagName}></\${litTagName}>\` - `, - filename: 'front_end/components/test.ts', - // Two errors: first uses lowercase "foo", second accesses the static directly, not via the class. - errors: [ - {messageId: 'invalidStaticProperty', column: 23, line: 5}, - {messageId: 'invalidStaticProperty', column: 43, line: 5} - ] - }, - ] -});