🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@yafh/eslint-plugin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yafh/eslint-plugin - npm Package Compare versions

Comparing version
0.2.0
to
0.3.0
+1
-219
dist/index.js

@@ -1,219 +0,1 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/rules/icon-component-prefix.ts
var _types = require('@typescript-eslint/types');
// src/utils.ts
var _utils = require('@typescript-eslint/utils');
var createRule = _utils.ESLintUtils.RuleCreator((name5) => name5);
function isSourceOf(node, matcher) {
const source = node.source.value;
if (matcher instanceof RegExp)
return matcher.test(source);
else if (typeof matcher === "string")
return source.startsWith(matcher);
else
return matcher.some((m) => source.startsWith(m));
}
function isAliasImportSpecifier(node) {
return node.type === _types.AST_NODE_TYPES.ImportSpecifier && (node.imported.range[0] !== node.local.range[0] || node.imported.range[1] !== node.local.range[1]);
}
// src/rules/icon-component-prefix.ts
var name = "icon-component-prefix";
var icon_component_prefix_default = createRule({
name,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
fixable: "code",
schema: [
{
type: ["string", "array"],
description: "Icon Component source matcher"
},
{
type: ["string"],
description: "prefix"
}
],
messages: {
missingIconComponentPrefix: "Expect icon component prefix '{{prefix}}'"
}
},
defaultOptions: [["@ricons", "@vicons", "@v2icons", "@sicons"], "Icon"],
create: (context, options) => {
return {
ImportDeclaration(node) {
const [matcher, prefix] = options;
if (!isSourceOf(node, matcher))
return;
for (const specifier of node.specifiers) {
if (!specifier.local.name.startsWith(prefix)) {
context.report({
loc: specifier.loc,
messageId: "missingIconComponentPrefix",
data: {
prefix
},
fix(fixer) {
const caseMiss = RegExp(`^${prefix}`, "i").test(specifier.local.name);
let code = prefix + (caseMiss ? specifier.local.name.substring(prefix.length) : specifier.local.name);
if (specifier.type === _types.AST_NODE_TYPES.ImportSpecifier && !isAliasImportSpecifier(specifier))
code = `${specifier.local.name} as ${code}`;
return fixer.replaceText(specifier.local, code);
}
});
}
}
}
};
}
});
// src/rules/no-index-vue.ts
var _path = require('path');
var name2 = "no-index-vue";
var no_index_vue_default = createRule(
{
name: name2,
meta: {
type: "problem",
docs: {
description: "",
recommended: "recommended"
},
schema: [],
messages: {
noIndexVue: "Do not use index.vue"
}
},
defaultOptions: [],
create: (context) => {
return {
Program() {
if (_path.basename.call(void 0, context.getFilename()).toLocaleLowerCase() === "index.vue") {
context.report({
loc: {
line: 1,
column: 0
},
messageId: "noIndexVue"
});
}
}
};
}
}
);
// src/rules/no-multiple-slash-comment.ts
var name3 = "no-multiple-slash-comment";
function isTripleSlashDirectives(comment) {
if (comment.type !== _utils.AST_TOKEN_TYPES.Line)
return false;
return /^\/\s*<(amd-module|amd-dependency|reference){1}.*\/>\s*$/.test(comment.value);
}
var no_multiple_slash_comment_default = createRule({
name: name3,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
fixable: "code",
schema: [],
messages: {
noMultipleSlashComment: "Do not use multiple slashes for single line comments."
}
},
defaultOptions: [],
create: (context) => {
const sourceCode = context.getSourceCode();
return {
Program() {
sourceCode.getAllComments().filter((comment) => comment.type === "Line").filter((comment) => !isTripleSlashDirectives(comment)).filter((comment) => /^\/+/.test(comment.value)).forEach((comment) => {
context.report({
node: comment,
messageId: "noMultipleSlashComment",
fix: (fixer) => fixer.replaceText(comment, `//${comment.value.replace(/^\/+/, "")}`)
});
});
}
};
}
});
// src/rules/pascal-case-component-name.ts
var _pascalcase = require('pascal-case');
var name4 = "pascal-case-component-name";
var pascal_case_component_name_default = createRule(
{
name: name4,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
schema: [],
messages: {
missingPascalCaseComponentName: "Vue component name must be PascalCase. e.g. {{pascalCase}}"
}
},
defaultOptions: [],
create: (context) => {
return {
Program() {
const baseName = _path.basename.call(void 0, context.getFilename());
if (!baseName.endsWith(".vue"))
return;
const fileName = baseName.split(".")[0];
const pascalCaseName = _pascalcase.pascalCase.call(void 0, fileName, { transform: _pascalcase.pascalCaseTransformMerge });
if (fileName !== pascalCaseName) {
context.report({
loc: {
line: 1,
column: 0
},
messageId: "missingPascalCaseComponentName",
data: {
pascalCase: pascalCaseName + baseName.slice(fileName.length)
}
});
}
}
};
}
}
);
// src/index.ts
var src_default = {
rules: {
"icon-component-prefix": icon_component_prefix_default,
"no-index-vue": no_index_vue_default,
"no-multiple-slash-comment": no_multiple_slash_comment_default,
"pascal-case-component-name": pascal_case_component_name_default
},
configs: {
recommended: {
plugins: ["@yafh"],
rules: {
"@yafh/icon-component-prefix": "error",
"@yafh/no-multiple-slash-comment": "error",
// vue
"@yafh/no-index-vue": "error",
"@yafh/pascal-case-component-name": "error"
}
}
}
};
exports.default = src_default;
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _types = require('@typescript-eslint/types');var _utils = require('@typescript-eslint/utils');var r=_utils.ESLintUtils.RuleCreator(e=>e);function l(e,t){let o=e.source.value;return t instanceof RegExp?t.test(o):typeof t=="string"?o.startsWith(t):t.some(s=>o.startsWith(s))}function u(e,t){let o=e.source.value;return t.test(o)}function f(e){return e.type===_types.AST_NODE_TYPES.ImportSpecifier&&(e.imported.range[0]!==e.local.range[0]||e.imported.range[1]!==e.local.range[1])}var T="icon-component-prefix",d=r({name:T,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[{type:["string","array"],description:"Icon Component source matcher"},{type:["string"],description:"prefix"}],messages:{missingIconComponentPrefix:"Expect icon component prefix '{{prefix}}'"}},defaultOptions:[["@ricons","@vicons","@v2icons","@sicons"],"Icon"],create:(e,t)=>({ImportDeclaration(o){let[s,i]=t;if(l(o,s))for(let n of o.specifiers)n.local.name.startsWith(i)||e.report({loc:n.loc,messageId:"missingIconComponentPrefix",data:{prefix:i},fix(m){let c=RegExp(`^${i}`,"i").test(n.local.name),a=i+(c?n.local.name.substring(i.length):n.local.name);return n.type===_types.AST_NODE_TYPES.ImportSpecifier&&!f(n)&&(a=`${n.local.name} as ${a}`),m.replaceText(n.local,a)}})}})});var _path = require('path');var E="no-index-vue",g=r({name:E,meta:{type:"problem",docs:{description:"",recommended:"recommended"},schema:[],messages:{noIndexVue:"Do not use index.vue"}},defaultOptions:[],create:e=>({Program(){_path.basename.call(void 0, e.getFilename()).toLocaleLowerCase()==="index.vue"&&e.report({loc:{line:1,column:0},messageId:"noIndexVue"})}})});var v="no-multiple-slash-comment";function b(e){return e.type!==_utils.AST_TOKEN_TYPES.Line?!1:/^\/\s*<(amd-module|amd-dependency|reference){1}.*\/>\s*$/.test(e.value)}var x=r({name:v,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[],messages:{noMultipleSlashComment:"Do not use multiple slashes for single line comments."}},defaultOptions:[],create:e=>{let t=e.getSourceCode();return{Program(){t.getAllComments().filter(o=>o.type==="Line").filter(o=>!b(o)).filter(o=>/^\/+/.test(o.value)).forEach(o=>{e.report({node:o,messageId:"noMultipleSlashComment",fix:s=>s.replaceText(o,`//${o.value.replace(/^\/+/,"")}`)})})}}}});var _pascalcase = require('pascal-case');var N="pascal-case-component-name",C=r({name:N,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},schema:[],messages:{missingPascalCaseComponentName:"Vue component name must be PascalCase. e.g. {{pascalCase}}"}},defaultOptions:[],create:e=>({Program(){let t=_path.basename.call(void 0, e.getFilename());if(!t.endsWith(".vue"))return;let o=t.split(".")[0],s=_pascalcase.pascalCase.call(void 0, o,{transform:_pascalcase.pascalCaseTransformMerge});o!==s&&e.report({loc:{line:1,column:0},messageId:"missingPascalCaseComponentName",data:{pascalCase:s+t.slice(o.length)}})}})});var j="no-cjs-icon-component",L=/^@(r|v|v2)icons/i;function A(e){var c;let[t,o,s,...i]=e.split("/"),n=o!=="utils"&&!["es","",void 0].includes((c=s==null?void 0:s.trim())==null?void 0:c.toLocaleLowerCase());return{org:t,iconSet:o,isUtil:o==="utils",shouldFix:n,fixSource:()=>{var p;if(!n)return e;let a=[t,o,"es"];return((p=s==null?void 0:s.trim())==null?void 0:p.toLocaleLowerCase())!=="lib"&&a.push(s),a.push(...i),a.join("/")}}}var I=r({name:j,meta:{type:"problem",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[],messages:{noCjsIconCompnoent:"Do not import icon components maybe cjs."}},defaultOptions:[],create:e=>({ImportDeclaration(t){if(!u(t,L))return;let{shouldFix:o,fixSource:s}=A(t.source.value);o&&e.report({messageId:"noCjsIconCompnoent",node:t,fix(i){return i.replaceText(t.source,`'${s()}'`)}})}})});var ne={rules:{"icon-component-prefix":d,"no-index-vue":g,"no-multiple-slash-comment":x,"pascal-case-component-name":C,"no-cjs-icon-component":I},configs:{recommended:{plugins:["@yafh"],rules:{"@yafh/icon-component-prefix":"error","@yafh/no-cjs-icon-component":"error","@yafh/no-multiple-slash-comment":"error","@yafh/no-index-vue":"error","@yafh/pascal-case-component-name":"error"}}}};exports.default = ne;

@@ -1,219 +0,1 @@

// src/rules/icon-component-prefix.ts
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/types";
// src/utils.ts
import { ESLintUtils } from "@typescript-eslint/utils";
import { AST_NODE_TYPES } from "@typescript-eslint/types";
var createRule = ESLintUtils.RuleCreator((name5) => name5);
function isSourceOf(node, matcher) {
const source = node.source.value;
if (matcher instanceof RegExp)
return matcher.test(source);
else if (typeof matcher === "string")
return source.startsWith(matcher);
else
return matcher.some((m) => source.startsWith(m));
}
function isAliasImportSpecifier(node) {
return node.type === AST_NODE_TYPES.ImportSpecifier && (node.imported.range[0] !== node.local.range[0] || node.imported.range[1] !== node.local.range[1]);
}
// src/rules/icon-component-prefix.ts
var name = "icon-component-prefix";
var icon_component_prefix_default = createRule({
name,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
fixable: "code",
schema: [
{
type: ["string", "array"],
description: "Icon Component source matcher"
},
{
type: ["string"],
description: "prefix"
}
],
messages: {
missingIconComponentPrefix: "Expect icon component prefix '{{prefix}}'"
}
},
defaultOptions: [["@ricons", "@vicons", "@v2icons", "@sicons"], "Icon"],
create: (context, options) => {
return {
ImportDeclaration(node) {
const [matcher, prefix] = options;
if (!isSourceOf(node, matcher))
return;
for (const specifier of node.specifiers) {
if (!specifier.local.name.startsWith(prefix)) {
context.report({
loc: specifier.loc,
messageId: "missingIconComponentPrefix",
data: {
prefix
},
fix(fixer) {
const caseMiss = RegExp(`^${prefix}`, "i").test(specifier.local.name);
let code = prefix + (caseMiss ? specifier.local.name.substring(prefix.length) : specifier.local.name);
if (specifier.type === AST_NODE_TYPES2.ImportSpecifier && !isAliasImportSpecifier(specifier))
code = `${specifier.local.name} as ${code}`;
return fixer.replaceText(specifier.local, code);
}
});
}
}
}
};
}
});
// src/rules/no-index-vue.ts
import { basename } from "node:path";
var name2 = "no-index-vue";
var no_index_vue_default = createRule(
{
name: name2,
meta: {
type: "problem",
docs: {
description: "",
recommended: "recommended"
},
schema: [],
messages: {
noIndexVue: "Do not use index.vue"
}
},
defaultOptions: [],
create: (context) => {
return {
Program() {
if (basename(context.getFilename()).toLocaleLowerCase() === "index.vue") {
context.report({
loc: {
line: 1,
column: 0
},
messageId: "noIndexVue"
});
}
}
};
}
}
);
// src/rules/no-multiple-slash-comment.ts
import { AST_TOKEN_TYPES } from "@typescript-eslint/utils";
var name3 = "no-multiple-slash-comment";
function isTripleSlashDirectives(comment) {
if (comment.type !== AST_TOKEN_TYPES.Line)
return false;
return /^\/\s*<(amd-module|amd-dependency|reference){1}.*\/>\s*$/.test(comment.value);
}
var no_multiple_slash_comment_default = createRule({
name: name3,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
fixable: "code",
schema: [],
messages: {
noMultipleSlashComment: "Do not use multiple slashes for single line comments."
}
},
defaultOptions: [],
create: (context) => {
const sourceCode = context.getSourceCode();
return {
Program() {
sourceCode.getAllComments().filter((comment) => comment.type === "Line").filter((comment) => !isTripleSlashDirectives(comment)).filter((comment) => /^\/+/.test(comment.value)).forEach((comment) => {
context.report({
node: comment,
messageId: "noMultipleSlashComment",
fix: (fixer) => fixer.replaceText(comment, `//${comment.value.replace(/^\/+/, "")}`)
});
});
}
};
}
});
// src/rules/pascal-case-component-name.ts
import { basename as basename2 } from "node:path";
import { pascalCase, pascalCaseTransformMerge } from "pascal-case";
var name4 = "pascal-case-component-name";
var pascal_case_component_name_default = createRule(
{
name: name4,
meta: {
type: "suggestion",
docs: {
description: "",
recommended: "recommended"
},
schema: [],
messages: {
missingPascalCaseComponentName: "Vue component name must be PascalCase. e.g. {{pascalCase}}"
}
},
defaultOptions: [],
create: (context) => {
return {
Program() {
const baseName = basename2(context.getFilename());
if (!baseName.endsWith(".vue"))
return;
const fileName = baseName.split(".")[0];
const pascalCaseName = pascalCase(fileName, { transform: pascalCaseTransformMerge });
if (fileName !== pascalCaseName) {
context.report({
loc: {
line: 1,
column: 0
},
messageId: "missingPascalCaseComponentName",
data: {
pascalCase: pascalCaseName + baseName.slice(fileName.length)
}
});
}
}
};
}
}
);
// src/index.ts
var src_default = {
rules: {
"icon-component-prefix": icon_component_prefix_default,
"no-index-vue": no_index_vue_default,
"no-multiple-slash-comment": no_multiple_slash_comment_default,
"pascal-case-component-name": pascal_case_component_name_default
},
configs: {
recommended: {
plugins: ["@yafh"],
rules: {
"@yafh/icon-component-prefix": "error",
"@yafh/no-multiple-slash-comment": "error",
// vue
"@yafh/no-index-vue": "error",
"@yafh/pascal-case-component-name": "error"
}
}
}
};
export {
src_default as default
};
import{AST_NODE_TYPES as h}from"@typescript-eslint/types";import{ESLintUtils as S}from"@typescript-eslint/utils";import{AST_NODE_TYPES as y}from"@typescript-eslint/types";var r=S.RuleCreator(e=>e);function l(e,t){let o=e.source.value;return t instanceof RegExp?t.test(o):typeof t=="string"?o.startsWith(t):t.some(s=>o.startsWith(s))}function u(e,t){let o=e.source.value;return t.test(o)}function f(e){return e.type===y.ImportSpecifier&&(e.imported.range[0]!==e.local.range[0]||e.imported.range[1]!==e.local.range[1])}var T="icon-component-prefix",d=r({name:T,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[{type:["string","array"],description:"Icon Component source matcher"},{type:["string"],description:"prefix"}],messages:{missingIconComponentPrefix:"Expect icon component prefix '{{prefix}}'"}},defaultOptions:[["@ricons","@vicons","@v2icons","@sicons"],"Icon"],create:(e,t)=>({ImportDeclaration(o){let[s,i]=t;if(l(o,s))for(let n of o.specifiers)n.local.name.startsWith(i)||e.report({loc:n.loc,messageId:"missingIconComponentPrefix",data:{prefix:i},fix(m){let c=RegExp(`^${i}`,"i").test(n.local.name),a=i+(c?n.local.name.substring(i.length):n.local.name);return n.type===h.ImportSpecifier&&!f(n)&&(a=`${n.local.name} as ${a}`),m.replaceText(n.local,a)}})}})});import{basename as O}from"node:path";var E="no-index-vue",g=r({name:E,meta:{type:"problem",docs:{description:"",recommended:"recommended"},schema:[],messages:{noIndexVue:"Do not use index.vue"}},defaultOptions:[],create:e=>({Program(){O(e.getFilename()).toLocaleLowerCase()==="index.vue"&&e.report({loc:{line:1,column:0},messageId:"noIndexVue"})}})});import{AST_TOKEN_TYPES as M}from"@typescript-eslint/utils";var v="no-multiple-slash-comment";function b(e){return e.type!==M.Line?!1:/^\/\s*<(amd-module|amd-dependency|reference){1}.*\/>\s*$/.test(e.value)}var x=r({name:v,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[],messages:{noMultipleSlashComment:"Do not use multiple slashes for single line comments."}},defaultOptions:[],create:e=>{let t=e.getSourceCode();return{Program(){t.getAllComments().filter(o=>o.type==="Line").filter(o=>!b(o)).filter(o=>/^\/+/.test(o.value)).forEach(o=>{e.report({node:o,messageId:"noMultipleSlashComment",fix:s=>s.replaceText(o,`//${o.value.replace(/^\/+/,"")}`)})})}}}});import{basename as P}from"node:path";import{pascalCase as R,pascalCaseTransformMerge as D}from"pascal-case";var N="pascal-case-component-name",C=r({name:N,meta:{type:"suggestion",docs:{description:"",recommended:"recommended"},schema:[],messages:{missingPascalCaseComponentName:"Vue component name must be PascalCase. e.g. {{pascalCase}}"}},defaultOptions:[],create:e=>({Program(){let t=P(e.getFilename());if(!t.endsWith(".vue"))return;let o=t.split(".")[0],s=R(o,{transform:D});o!==s&&e.report({loc:{line:1,column:0},messageId:"missingPascalCaseComponentName",data:{pascalCase:s+t.slice(o.length)}})}})});var j="no-cjs-icon-component",L=/^@(r|v|v2)icons/i;function A(e){var c;let[t,o,s,...i]=e.split("/"),n=o!=="utils"&&!["es","",void 0].includes((c=s==null?void 0:s.trim())==null?void 0:c.toLocaleLowerCase());return{org:t,iconSet:o,isUtil:o==="utils",shouldFix:n,fixSource:()=>{var p;if(!n)return e;let a=[t,o,"es"];return((p=s==null?void 0:s.trim())==null?void 0:p.toLocaleLowerCase())!=="lib"&&a.push(s),a.push(...i),a.join("/")}}}var I=r({name:j,meta:{type:"problem",docs:{description:"",recommended:"recommended"},fixable:"code",schema:[],messages:{noCjsIconCompnoent:"Do not import icon components maybe cjs."}},defaultOptions:[],create:e=>({ImportDeclaration(t){if(!u(t,L))return;let{shouldFix:o,fixSource:s}=A(t.source.value);o&&e.report({messageId:"noCjsIconCompnoent",node:t,fix(i){return i.replaceText(t.source,`'${s()}'`)}})}})});var ne={rules:{"icon-component-prefix":d,"no-index-vue":g,"no-multiple-slash-comment":x,"pascal-case-component-name":C,"no-cjs-icon-component":I},configs:{recommended:{plugins:["@yafh"],rules:{"@yafh/icon-component-prefix":"error","@yafh/no-cjs-icon-component":"error","@yafh/no-multiple-slash-comment":"error","@yafh/no-index-vue":"error","@yafh/pascal-case-component-name":"error"}}}};export{ne as default};
+1
-1
{
"name": "@yafh/eslint-plugin",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Eslint plugin for YanAndFish",