diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bbc4fbb..2d98616 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -1,6 +1,6 @@ name: Node CI -on: [push] +on: [push, pull_request] jobs: build: diff --git a/CODEOWNERS b/CODEOWNERS index e6bf555..68f394d 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @github/web-systems-reviewers +* @github/primer-reviewers diff --git a/docs/rules/no-exports-with-element.md b/docs/rules/no-exports-with-element.md index 280e632..ec39d3e 100644 --- a/docs/rules/no-exports-with-element.md +++ b/docs/rules/no-exports-with-element.md @@ -33,7 +33,7 @@ export class FooBarElement extends HTMLElement { // foo-bar-element.js import {myHelper} from './helpers.js' export class FooReadyEvent extends Event { - // ... + // ... } export class FooBarElement extends HTMLElement { diff --git a/lib/rules/file-name-matches-element.js b/lib/rules/file-name-matches-element.js index a5ff4ef..c6b897e 100644 --- a/lib/rules/file-name-matches-element.js +++ b/lib/rules/file-name-matches-element.js @@ -48,8 +48,11 @@ module.exports = { if (!hasFileName(context)) return {} return { [s.HTMLElementClass](node) { - const name = node.id.name - const names = [name] + const name = node.id?.name + const names = [] + if (name) { + names.push(name) + } const filename = basename(context.getFilename(), extname(context.getFilename())) const transforms = [].concat(context.options?.[0]?.transform || ['kebab', 'pascal']) const suffixes = [].concat(context.options?.[0]?.suffix || []) @@ -66,7 +69,7 @@ module.exports = { allowedFileNames.add(transformFuncs[transform](className)) } } - if (!allowedFileNames.has(filename)) { + if (allowedFileNames.size && !allowedFileNames.has(filename)) { const allowed = Array.from(allowedFileNames).join('" or "') context.report(node, `File name should be "${allowed}" but was "${filename}"`) } diff --git a/package-lock.json b/package-lock.json index 403e041..26f5080 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "eslint-plugin-custom-elements", "version": "0.0.5", "license": "MIT", "devDependencies": { diff --git a/test/file-name-matches-element.js b/test/file-name-matches-element.js index 9677222..0b736f0 100644 --- a/test/file-name-matches-element.js +++ b/test/file-name-matches-element.js @@ -51,6 +51,10 @@ ruleTester.run('file-name-matches-element', rule, { filename: 'components/foo/foo-bar.ts', options: [{transform: 'kebab', suffix: ['Controller']}], }, + { + code: 'window.customElements.define("foo-bar", class extends HTMLElement {})', + filename: 'any.js', + }, ], invalid: [ {