@eslint-react/shared
Advanced tools
Comparing version 0.9.8-beta.0 to 0.9.8-beta.1
@@ -369,2 +369,28 @@ import * as valibot from 'valibot'; | ||
export { type ESLintReactSettings, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, NPM_SCOPE, RE_JAVASCRIPT_PROTOCOL, WEBSITE_URL }; | ||
type RecommendationBuilder = (name: string) => string; | ||
declare class CaseValidator { | ||
#private; | ||
constructor(expression: RegExp, ignorePatterns: RegExp[], recommendationBuilder?: RecommendationBuilder); | ||
getRecommendedName(name: string): string; | ||
validate(name: string): boolean; | ||
} | ||
declare const getCaseValidator: (ruleName: string, ignorePattern?: string[]) => CaseValidator; | ||
interface Rule { | ||
expression: RegExp; | ||
recommendationBuilder?: (name: string) => string; | ||
} | ||
interface PresetRules { | ||
[key: string]: Required<Rule> | undefined; | ||
CONSTANT_CASE: Required<Rule>; | ||
PascalCase: Required<Rule>; | ||
camelCase: Required<Rule>; | ||
"kebab-case": Required<Rule>; | ||
snake_case: Required<Rule>; | ||
} | ||
declare const presetRules: PresetRules; | ||
declare const getRule: (expression: string, preset?: PresetRules) => Rule; | ||
declare const splitName: (name: string) => string[]; | ||
export { CaseValidator, type ESLintReactSettings, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, HOST_HTML_COMPONENT_TYPES, HOST_SVG_COMPONENT_TYPES, NPM_SCOPE, RE_JAVASCRIPT_PROTOCOL, WEBSITE_URL, getCaseValidator, getRule, presetRules, splitName }; |
@@ -221,2 +221,140 @@ 'use strict'; | ||
/* | ||
* Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/split-name.ts | ||
* Split the file/variable name written in camelCase, kebab-case, PascalCase, and snake_case. | ||
*/ const splitName = (name)=>{ | ||
return name.replaceAll("_", "-").replaceAll(/([\da-z])([A-Z])|([A-Z])([A-Z])(?=[a-z])/gu, "$1$3-$2$4").toLowerCase().split("-"); | ||
}; | ||
/* eslint-disable no-restricted-syntax */ /* eslint-disable security/detect-object-injection */ /* eslint-disable security/detect-non-literal-regexp */ // Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/preset-rules.ts | ||
const presetRules = { | ||
PascalCase: { | ||
expression: /^[A-Z][\dA-Za-z]*$/u, | ||
recommendationBuilder: (name)=>{ | ||
return splitName(name).map((word)=>{ | ||
const [first, ...rest] = word; | ||
return `${first?.toUpperCase() ?? ""}${rest.join("")}`; | ||
}).join(""); | ||
} | ||
}, | ||
camelCase: { | ||
expression: /^[a-z][\dA-Za-z]*$/u, | ||
recommendationBuilder: (name)=>{ | ||
return splitName(name).map((word, i)=>{ | ||
if (i === 0) { | ||
return word; | ||
} | ||
const [first, ...rest] = word; | ||
return `${first?.toUpperCase() ?? ""}${rest.join("")}`; | ||
}).join(""); | ||
} | ||
}, | ||
"kebab-case": { | ||
expression: /^[a-z][\d\-a-z]*$/u, | ||
recommendationBuilder: (name)=>{ | ||
return splitName(name).join("-"); | ||
} | ||
}, | ||
snake_case: { | ||
expression: /^[a-z][\d_a-z]*$/u, | ||
recommendationBuilder: (name)=>{ | ||
return splitName(name).join("_"); | ||
} | ||
}, | ||
// eslint-disable-next-line perfectionist/sort-objects | ||
CONSTANT_CASE: { | ||
expression: /^[A-Z][\d_A-Z]*$/u, | ||
recommendationBuilder: (name)=>{ | ||
return splitName(name).join("_").toUpperCase(); | ||
} | ||
} | ||
}; | ||
const getRule = (expression, preset = presetRules)=>{ | ||
const rule = preset[expression]; | ||
return rule ?? { | ||
expression: new RegExp(`^${expression}$`, "u") | ||
}; | ||
}; | ||
/* eslint-disable functional/no-this-expressions */ /* eslint-disable functional/prefer-immutable-types */ /* eslint-disable functional/no-expression-statements */ /* eslint-disable functional/no-classes */ /* eslint-disable functional/no-throw-statements */ /* eslint-disable security/detect-non-literal-regexp */ // Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/case-validator.ts | ||
function _check_private_redeclaration(obj, privateCollection) { | ||
if (privateCollection.has(obj)) { | ||
throw new TypeError("Cannot initialize the same private elements twice on an object"); | ||
} | ||
} | ||
function _class_apply_descriptor_get(receiver, descriptor) { | ||
if (descriptor.get) { | ||
return descriptor.get.call(receiver); | ||
} | ||
return descriptor.value; | ||
} | ||
function _class_apply_descriptor_set(receiver, descriptor, value) { | ||
if (descriptor.set) { | ||
descriptor.set.call(receiver, value); | ||
} else { | ||
if (!descriptor.writable) { | ||
throw new TypeError("attempted to set read only private field"); | ||
} | ||
descriptor.value = value; | ||
} | ||
} | ||
function _class_extract_field_descriptor(receiver, privateMap, action) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to " + action + " private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
} | ||
function _class_private_field_get(receiver, privateMap) { | ||
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get"); | ||
return _class_apply_descriptor_get(receiver, descriptor); | ||
} | ||
function _class_private_field_init(obj, privateMap, value) { | ||
_check_private_redeclaration(obj, privateMap); | ||
privateMap.set(obj, value); | ||
} | ||
function _class_private_field_set(receiver, privateMap, value) { | ||
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set"); | ||
_class_apply_descriptor_set(receiver, descriptor, value); | ||
return value; | ||
} | ||
var _expression = /*#__PURE__*/ new WeakMap(), _ignorePatterns = /*#__PURE__*/ new WeakMap(), _recommendationBuilder = /*#__PURE__*/ new WeakMap(); | ||
class CaseValidator { | ||
getRecommendedName(name) { | ||
const recommendedName = _class_private_field_get(this, _recommendationBuilder).call(this, name); | ||
if (_class_private_field_get(this, _expression).test(recommendedName)) { | ||
return recommendedName; | ||
} | ||
throw new Error("Failed to build recommendation."); | ||
} | ||
validate(name) { | ||
if (_class_private_field_get(this, _ignorePatterns).some((re)=>re.test(name))) { | ||
return true; | ||
} | ||
return _class_private_field_get(this, _expression).test(name); | ||
} | ||
constructor(expression, ignorePatterns, recommendationBuilder = ()=>{ | ||
throw new Error("Not implemented"); | ||
}){ | ||
_class_private_field_init(this, _expression, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_class_private_field_init(this, _ignorePatterns, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_class_private_field_init(this, _recommendationBuilder, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_class_private_field_set(this, _expression, expression); | ||
_class_private_field_set(this, _ignorePatterns, ignorePatterns); | ||
_class_private_field_set(this, _recommendationBuilder, recommendationBuilder); | ||
} | ||
} | ||
const getCaseValidator = (ruleName, ignorePattern = [])=>{ | ||
const { expression, recommendationBuilder } = getRule(ruleName); | ||
return new CaseValidator(expression, ignorePattern.map((pattern)=>new RegExp(`^${pattern}$`, "u")), recommendationBuilder); | ||
}; | ||
Object.defineProperty(exports, "parse", { | ||
@@ -230,2 +368,3 @@ enumerable: true, | ||
}); | ||
exports.CaseValidator = CaseValidator; | ||
exports.ESLintReactSettingsSchema = ESLintReactSettingsSchema; | ||
@@ -239,1 +378,5 @@ exports.ESLintSettingsSchema = ESLintSettingsSchema; | ||
exports.WEBSITE_URL = WEBSITE_URL; | ||
exports.getCaseValidator = getCaseValidator; | ||
exports.getRule = getRule; | ||
exports.presetRules = presetRules; | ||
exports.splitName = splitName; |
{ | ||
"name": "@eslint-react/shared", | ||
"version": "0.9.8-beta.0", | ||
"version": "0.9.8-beta.1", | ||
"description": "ESLint React's shared data and constants.", | ||
@@ -38,14 +38,10 @@ "homepage": "https://github.com/rel1cx/eslint-react", | ||
"dependencies": { | ||
"@typescript-eslint/utils": "6.14.0", | ||
"dedent": "1.5.1", | ||
"deepmerge-ts": "5.1.0", | ||
"short-unique-id": "5.0.3", | ||
"tslib": "2.6.2", | ||
"valibot": "0.24.1", | ||
"@eslint-react/tools": "0.9.8-beta.0", | ||
"@eslint-react/types": "0.9.8-beta.0" | ||
"valibot": "0.24.1" | ||
}, | ||
"devDependencies": { | ||
"type-fest": "4.8.3" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c rollup.config.ts --configPlugin swc3 && cp dist/index.d.ts dist/index.d.mts", | ||
"build:docs": "typedoc && dprint fmt ./docs/**/*.md", | ||
"build:docs": "typedoc", | ||
"lint:publish": "publint", | ||
@@ -52,0 +48,0 @@ "lint:type": "tsc --noEmit" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81277
1
1495
1
160947
- Removed@eslint-react/tools@0.9.8-beta.0
- Removed@eslint-react/types@0.9.8-beta.0
- Removed@typescript-eslint/utils@6.14.0
- Removeddedent@1.5.1
- Removeddeepmerge-ts@5.1.0
- Removedshort-unique-id@5.0.3
- Removedtslib@2.6.2
- Removed@eslint-community/eslint-utils@4.4.1(transitive)
- Removed@eslint-community/regexpp@4.12.1(transitive)
- Removed@eslint-react/tools@0.9.8-beta.0(transitive)
- Removed@eslint-react/types@0.9.8-beta.0(transitive)
- Removed@eslint/eslintrc@2.1.4(transitive)
- Removed@eslint/js@8.57.1(transitive)
- Removed@humanwhocodes/config-array@0.13.0(transitive)
- Removed@humanwhocodes/module-importer@1.0.1(transitive)
- Removed@humanwhocodes/object-schema@2.0.3(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removed@types/semver@7.5.8(transitive)
- Removed@typescript-eslint/scope-manager@6.14.0(transitive)
- Removed@typescript-eslint/types@6.14.0(transitive)
- Removed@typescript-eslint/typescript-estree@6.14.0(transitive)
- Removed@typescript-eslint/utils@6.14.0(transitive)
- Removed@typescript-eslint/visitor-keys@6.14.0(transitive)
- Removed@ungap/structured-clone@1.2.1(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-jsx@5.3.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedargparse@2.0.1(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbraces@3.0.3(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddedent@1.5.1(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddeepmerge-ts@5.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removeddoctrine@3.0.0(transitive)
- Removedeffect@2.0.0-next.60(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedeslint@8.57.1(transitive)
- Removedeslint-scope@7.2.2(transitive)
- Removedeslint-visitor-keys@3.4.3(transitive)
- Removedespree@9.6.1(transitive)
- Removedesquery@1.6.0(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@5.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfile-entry-cache@6.0.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedfind-up@5.0.0(transitive)
- Removedflat-cache@3.2.0(transitive)
- Removedflatted@3.3.2(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglob-parent@5.1.26.0.2(transitive)
- Removedglobals@13.24.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgraphemer@1.4.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-path-inside@3.0.3(transitive)
- Removedisexe@2.0.0(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlevn@0.4.1(transitive)
- Removedlocate-path@6.0.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedms@2.1.3(transitive)
- Removednatural-compare@1.4.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedoptionator@0.9.4(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedp-locate@5.0.0(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedprelude-ls@1.2.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsemver@7.6.3(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedshort-unique-id@5.0.3(transitive)
- Removedslash@3.0.0(transitive)
- Removedstring-ts@1.3.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedstrip-json-comments@3.1.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedtext-table@0.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedts-api-utils@1.4.3(transitive)
- Removedts-pattern@5.0.6(transitive)
- Removedtslib@2.6.2(transitive)
- Removedtype-check@0.4.0(transitive)
- Removedtype-fest@0.20.2(transitive)
- Removedtypescript@5.7.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwhich@2.0.2(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyocto-queue@0.1.0(transitive)