@esri/eslint-plugin-calcite-components
Advanced tools
Comparing version 2.0.0-next.0 to 2.0.0-next.1
/* | ||
All material copyright ESRI, All Rights Reserved, unless otherwise specified. | ||
See https://github.com/Esri/calcite-design-system/blob/2.0.0-next.0/LICENSE.md for details. | ||
See https://github.com/Esri/calcite-design-system/blob/2.0.0-next.1/LICENSE.md for details. | ||
*/ | ||
'use strict'; | ||
var stencilEslintCore = require('stencil-eslint-core'); | ||
var utils = require('@typescript-eslint/utils'); | ||
const rule$2 = { | ||
const createRule$2 = utils.ESLintUtils.RuleCreator((name) => name); | ||
var banEvents = createRule$2({ | ||
name: "ban-events", | ||
defaultOptions: [], | ||
meta: { | ||
docs: { | ||
description: "This rule catches helps ban or warn against listened event types", | ||
category: "Consistency", | ||
description: "This rule helps ban or warn against listened event types", | ||
}, | ||
messages: { | ||
default: "{{message}}", | ||
}, | ||
schema: { | ||
@@ -38,8 +43,7 @@ type: "array", | ||
}, | ||
create: function (context) { | ||
const stencil = stencilEslintCore.stencilComponentContext(); | ||
create(context) { | ||
const bannedEventToMessageLookup = new Map(); | ||
context.options.forEach((option) => { | ||
const event = typeof option === "string" ? option : option.event; | ||
const message = typeof option === "string" ? null : option.message ?? null; | ||
const message = typeof option === "string" ? null : (option.message ?? null); | ||
bannedEventToMessageLookup.set(event, message); | ||
@@ -50,30 +54,27 @@ }); | ||
} | ||
function checkEvent(node, eventName) { | ||
if (bannedEventToMessageLookup.has(eventName)) { | ||
context.report({ | ||
node, | ||
messageId: "default", | ||
data: { | ||
message: buildMessage(eventName), | ||
}, | ||
}); | ||
} | ||
} | ||
return { | ||
...stencil.rules, | ||
"MethodDefinition > Decorator[expression.callee.name=Listen] Literal": (node) => { | ||
if (stencil.isComponent()) { | ||
const eventName = node.value; | ||
if (bannedEventToMessageLookup.has(eventName)) { | ||
context.report({ | ||
node, | ||
message: buildMessage(eventName), | ||
}); | ||
} | ||
} | ||
"ClassDeclaration[superClass.name=LitElement] CallExpression:matches([callee.property.name=addEventListener], [callee.property.name=removeEventListener])"(node) { | ||
const eventName = node.arguments[0].value; | ||
checkEvent(node, eventName); | ||
}, | ||
"CallExpression:matches([callee.property.name=addEventListener], [callee.property.name=removeEventListener])": (node) => { | ||
if (stencil.isComponent()) { | ||
const eventName = node.arguments[0].value; | ||
if (bannedEventToMessageLookup.has(eventName)) { | ||
context.report({ | ||
node, | ||
message: buildMessage(eventName), | ||
}); | ||
} | ||
} | ||
"ClassDeclaration[superClass.name=LitElement] CallExpression[callee.object.type=ThisExpression][callee.property.name=listen], CallExpression[callee.object.type=ThisExpression][callee.property.name=listenOn]"(node) { | ||
const eventName = node.arguments[1].value; | ||
checkEvent(node, eventName); | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
const createRule$1 = utils.ESLintUtils.RuleCreator((name) => name); | ||
function isCreateElement(node) { | ||
@@ -88,9 +89,13 @@ return (node?.callee?.type === "MemberExpression" && | ||
} | ||
const rule$1 = { | ||
var noDynamicCreateelement = createRule$1({ | ||
name: "no-dynamic-createelement", | ||
defaultOptions: [], | ||
meta: { | ||
docs: { | ||
description: "This ensures supporting components created with `document.createElement()` are auto-defined in Stencil's `components` output target.", | ||
recommended: true, | ||
description: "This rule ensures that calls to `document.createElement()` use string literals to avoid dynamic tag creation to enhance plugin compatibility.", | ||
}, | ||
fixable: "code", | ||
messages: { | ||
default: "Calls to document.createElement() should use string literals", | ||
}, | ||
schema: [], | ||
@@ -108,3 +113,3 @@ type: "problem", | ||
node, | ||
message: "Calls to document.createElement() should use string literals", | ||
messageId: "default", | ||
}); | ||
@@ -115,26 +120,31 @@ } | ||
}, | ||
}; | ||
}); | ||
const rule = { | ||
const createRule = utils.ESLintUtils.RuleCreator((name) => name); | ||
var strictBooleanAttributes = createRule({ | ||
name: "strict-boolean-attributes", | ||
meta: { | ||
docs: { | ||
description: "This rule catches Stencil boolean Props that would not be able to be set to false with HTML5-compliant attributes.", | ||
category: "Possible Errors", | ||
recommended: false, | ||
description: "This rule catches boolean properties decorated with @Prop() that are initialized to true.", | ||
}, | ||
messages: { | ||
default: "Boolean properties decorated with @property() should not be initialized to true", | ||
}, | ||
schema: [], | ||
type: "problem", | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
const stencil = stencilEslintCore.stencilComponentContext(); | ||
return { | ||
...stencil.rules, | ||
PropertyDefinition: (node) => { | ||
const propDecorator = stencilEslintCore.getDecorator(node, "Prop"); | ||
if (stencil.isComponent() && propDecorator) { | ||
const initializer = node.value?.value; | ||
if (initializer === true) { | ||
const decorators = node.decorators || []; | ||
const hasPropDecorator = decorators.some((decorator) => decorator.expression.type === "CallExpression" && | ||
decorator.expression.callee.type === "Identifier" && | ||
decorator.expression.callee.name === "property"); | ||
if (hasPropDecorator) { | ||
const initializer = node.value; | ||
if (initializer && initializer.type === "Literal" && initializer.value === true) { | ||
context.report({ | ||
node: node.key, | ||
message: `Boolean properties decorated with @Prop() should not be initialized to true`, | ||
messageId: "default", | ||
}); | ||
@@ -146,8 +156,8 @@ } | ||
}, | ||
}; | ||
}); | ||
var index$1 = { | ||
"ban-events": rule$2, | ||
"no-dynamic-createelement": rule$1, | ||
"strict-boolean-attributes": rule, | ||
"ban-events": banEvents, | ||
"no-dynamic-createelement": noDynamicCreateelement, | ||
"strict-boolean-attributes": strictBooleanAttributes, | ||
}; | ||
@@ -154,0 +164,0 @@ |
{ | ||
"name": "@esri/eslint-plugin-calcite-components", | ||
"version": "2.0.0-next.0", | ||
"version": "2.0.0-next.1", | ||
"description": "ESLint rules for @esri/calcite-components", | ||
@@ -22,5 +22,2 @@ "repository": { | ||
}, | ||
"dependencies": { | ||
"stencil-eslint-core": "0.4.1" | ||
}, | ||
"devDependencies": { | ||
@@ -30,2 +27,3 @@ "ts-node": "10.9.2" | ||
"peerDependencies": { | ||
"@typescript-eslint/utils": ">=8.0.0", | ||
"eslint": ">=8.0.0" | ||
@@ -37,3 +35,3 @@ }, | ||
}, | ||
"gitHead": "3ed2a1cc5e9b6f45bf5826477142d9a4698db73f" | ||
"gitHead": "5cf4cb52b7c2ff69022efcd52f4b22775818b437" | ||
} |
10598
188
+ Added@typescript-eslint/scope-manager@8.24.0(transitive)
+ Added@typescript-eslint/types@8.24.0(transitive)
+ Added@typescript-eslint/typescript-estree@8.24.0(transitive)
+ Added@typescript-eslint/utils@8.24.0(transitive)
+ Added@typescript-eslint/visitor-keys@8.24.0(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedts-api-utils@2.0.1(transitive)
- Removedstencil-eslint-core@0.4.1
- Removed@eslint/eslintrc@2.1.4(transitive)
- Removed@eslint/js@8.57.1(transitive)
- Removed@humanwhocodes/config-array@0.13.0(transitive)
- Removed@humanwhocodes/object-schema@2.0.3(transitive)
- Removed@typescript-eslint/parser@5.62.0(transitive)
- Removed@typescript-eslint/scope-manager@5.62.0(transitive)
- Removed@typescript-eslint/types@5.62.0(transitive)
- Removed@typescript-eslint/typescript-estree@5.62.0(transitive)
- Removed@typescript-eslint/visitor-keys@5.62.0(transitive)
- Removed@ungap/structured-clone@1.3.0(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedarray-union@2.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removeddoctrine@3.0.0(transitive)
- Removedeslint@8.57.1(transitive)
- Removedeslint-scope@7.2.2(transitive)
- Removedeslint-utils@3.0.0(transitive)
- Removedeslint-visitor-keys@2.1.0(transitive)
- Removedespree@9.6.1(transitive)
- Removedfile-entry-cache@6.0.1(transitive)
- Removedflat-cache@3.2.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobals@13.24.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgraphemer@1.4.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-path-inside@3.0.3(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedslash@3.0.0(transitive)
- Removedstencil-eslint-core@0.4.1(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedtext-table@0.2.0(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtsutils@3.21.0(transitive)
- Removedtype-fest@0.20.2(transitive)
- Removedwrappy@1.0.2(transitive)