Build: Separate eslint logic for **/*.ts files (#19852)
* build: move typescript specific eslint rules to the `**/*ts.` pattern to avoid errors for .js files * allow `Example` as class prefix * allow `example-` as custom element prefix * Removed `eslint-disable-next-line` comments from the Example classes. * Code formatting/tidy-up of Example classes --------- Co-authored-by: leekelleher <leekelleher@gmail.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const ALLOWED_PREFIXES = ['umb-', 'ufm-', 'test-', 'example-'];
|
||||
|
||||
/** @type {import('eslint').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
@@ -23,9 +25,8 @@ module.exports = {
|
||||
if (isCustomElementDecorator) {
|
||||
const elementName = node.arguments[0].value;
|
||||
|
||||
// check if the element name starts with 'umb-', 'ufm-', or 'test-', to be allow tests to have custom elements:
|
||||
const prefixes = ['umb-', 'ufm-', 'test-'];
|
||||
const isElementNameValid = prefixes.some((prefix) => elementName.startsWith(prefix));
|
||||
// check if the element name starts with an allowed prefix:
|
||||
const isElementNameValid = ALLOWED_PREFIXES.some((prefix) => elementName.startsWith(prefix));
|
||||
|
||||
if (!isElementNameValid) {
|
||||
context.report({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const ALLOWED_PREFIXES = ['Umb', 'Example'];
|
||||
|
||||
/** @type {import('eslint').Rule.RuleModule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
@@ -11,10 +13,10 @@ module.exports = {
|
||||
},
|
||||
create: function (context) {
|
||||
function checkClassName(node) {
|
||||
if (node.id && node.id.name && !node.id.name.startsWith('Umb')) {
|
||||
if (node.id && node.id.name && !ALLOWED_PREFIXES.some((prefix) => node.id.name.startsWith(prefix))) {
|
||||
context.report({
|
||||
node: node.id,
|
||||
message: 'Class declaration should be prefixed with "Umb"',
|
||||
message: `Class declaration should be prefixed with one of the following prefixes: ${ALLOWED_PREFIXES.join(', ')}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user