New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-smarthr

Package Overview
Dependencies
Maintainers
0
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-smarthr - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

rules/best-practice-for-tailwind-variants/index.js

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [1.3.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v1.2.0...eslint-plugin-smarthr-v1.3.0) (2025-02-21)
### Features
* tailwind-variantsの使い方をチェックするルールを追加 ([#480](https://github.com/kufu/tamatebako/issues/480)) ([1501f05](https://github.com/kufu/tamatebako/commit/1501f05e84492e7671a4dc95ef08b15360a1c309))
### Bug Fixes
* [a11y-input-has-name-attribute]Inputにreact-hook-formのregisterが指定されている場合はエラーにならないようにする ([#490](https://github.com/kufu/tamatebako/issues/490)) ([2fc6abe](https://github.com/kufu/tamatebako/commit/2fc6abe9515a06dbf7e823da556e045402298a1b))
## [1.2.0](https://github.com/kufu/tamatebako/compare/eslint-plugin-smarthr-v1.1.0...eslint-plugin-smarthr-v1.2.0) (2025-01-09)

@@ -7,0 +19,0 @@

8

package.json
{
"name": "eslint-plugin-smarthr",
"version": "1.2.0",
"version": "1.3.0",
"author": "SmartHR",

@@ -9,3 +9,3 @@ "license": "MIT",

"engines": {
"node": ">=20.18.1"
"node": ">=20.18.2"
},

@@ -30,3 +30,3 @@ "scripts": {

"devDependencies": {
"typescript-eslint": "^8.14.0"
"typescript-eslint": "^8.19.1"
},

@@ -42,3 +42,3 @@ "peerDependencies": {

],
"gitHead": "71d56c769bf74139d828b181bec39fb148d9b5ca"
"gitHead": "3c7f6f40f11714a9dd6cb88dc243d1b6973c6a93"
}

@@ -24,2 +24,3 @@ # eslint-plugin-smarthr

- [best-practice-for-remote-trigger-dialog](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-remote-trigger-dialog)
- [best-practice-for-tailwind-variants](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-tailwind-variants)
- [design-system-guideline-prohibit-double-icons](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/design-system-guideline-prohibit-double-icons)

@@ -26,0 +27,0 @@ - [format-import-path](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/format-import-path)

@@ -1,3 +0,22 @@

const { generateTagFormatter } = require('../../libs/format_styled_components');
const fs = require('fs')
const JSON5 = require('json5')
const { generateTagFormatter } = require('../../libs/format_styled_components')
const OPTION = (() => {
const file = `${process.cwd()}/package.json`
if (!fs.existsSync(file)) {
return {}
}
const json = JSON5.parse(fs.readFileSync(file))
const dependencies = [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {})]
return {
react_hook_form: dependencies.includes('react-hook-form'),
}
})()
const EXPECTED_NAMES = {

@@ -7,10 +26,10 @@ '(i|I)nput$': 'Input$',

'(s|S)elect$': 'Select$',
'InputFile$': 'InputFile$',
'RadioButton$': 'RadioButton$',
'RadioButtonPanel$': 'RadioButtonPanel$',
InputFile$: 'InputFile$',
RadioButton$: 'RadioButton$',
RadioButtonPanel$: 'RadioButtonPanel$',
'Check(b|B)ox$': 'CheckBox$',
'Combo(b|B)ox$': 'ComboBox$',
'(Date|Wareki)Picker$': '(Date|Wareki)Picker$',
'TimePicker$': 'TimePicker$',
'DropZone$': 'DropZone$',
TimePicker$: 'TimePicker$',
DropZone$: 'DropZone$',
}

@@ -22,6 +41,2 @@ const TARGET_TAG_NAME_REGEX = new RegExp(`(${Object.keys(EXPECTED_NAMES).join('|')})`)

const findNameAttr = (a) => a?.name?.name === 'name'
const findSpreadAttr = (a) => a.type === 'JSXSpreadAttribute'
const findRadioInput = (a) => a.name?.name === 'type' && a.value.value === 'radio'
const MESSAGE_PART_FORMAT = `"${INPUT_NAME_REGEX.toString()}"にmatchするフォーマットで命名してください`

@@ -43,3 +58,3 @@ const MESSAGE_UNDEFINED_NAME_PART = `

additionalProperties: false,
}
},
]

@@ -62,16 +77,40 @@

JSXOpeningElement: (node) => {
const nodeName = node.name.name || '';
const { name, attributes } = node
const nodeName = name.name || ''
if (nodeName.match(TARGET_TAG_NAME_REGEX)) {
const nameAttr = node.attributes.find(findNameAttr)
let nameAttr = null
let hasSpreadAttr = false
let hasReactHookFormRegisterSpreadAttr = false
let hasRadioInput = false
attributes.forEach((a) => {
if (a.type === 'JSXSpreadAttribute') {
hasSpreadAttr = true
if (hasReactHookFormRegisterSpreadAttr === false && a.argument?.callee?.name === 'register') {
hasReactHookFormRegisterSpreadAttr = true
}
} else {
switch (a.name?.name) {
case 'name': {
nameAttr = a
break
}
case 'type': {
if (a.value.value === 'radio') {
hasRadioInput = true
}
break
}
}
}
})
if (!nameAttr) {
if (
node.attributes.length === 0 ||
checkType !== 'allow-spread-attributes' ||
!node.attributes.some(findSpreadAttr)
!(OPTION.react_hook_form && hasReactHookFormRegisterSpreadAttr) &&
(attributes.length === 0 || checkType !== 'allow-spread-attributes' || !hasSpreadAttr)
) {
const isRadio =
nodeName.match(RADIO_BUTTON_REGEX) ||
(nodeName.match(INPUT_TAG_REGEX) && node.attributes.some(findRadioInput));
const isRadio = nodeName.match(RADIO_BUTTON_REGEX) || (nodeName.match(INPUT_TAG_REGEX) && hasRadioInput)

@@ -81,3 +120,3 @@ context.report({

message: `${nodeName} ${isRadio ? MESSAGE_UNDEFINED_FOR_RADIO : MESSAGE_UNDEFINED_FOR_NOT_RADIO}`,
});
})
}

@@ -91,3 +130,3 @@ } else {

message: `${nodeName} のname属性の値(${nameValue})${MESSAGE_NAME_FORMAT_SUFFIX}`,
});
})
}

@@ -97,5 +136,5 @@ }

},
};
}
},
};
module.exports.schema = SCHEMA;
}
module.exports.schema = SCHEMA
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc