-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: https://github.com/kufu/eslint-plugin-smarthr からファイルを移動 (#454)
- Loading branch information
Showing
112 changed files
with
9,523 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright 2024 SmartHR | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# eslint-plugin-smarthr | ||
|
||
- [a11y-anchor-has-href-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-anchor-has-href-attribute) | ||
- [a11y-clickable-element-has-text](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-clickable-element-has-text) | ||
- [a11y-delegate-element-has-role-presentation](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-delegate-element-has-role-presentation) | ||
- [a11y-form-control-in-form](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-form-control-in-form) | ||
- [a11y-heading-in-sectioning-content](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-heading-in-sectioning-content) | ||
- [a11y-image-has-alt-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-image-has-alt-attribute) | ||
- [a11y-input-has-name-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-input-has-name-attribute) | ||
- [a11y-input-in-form-control](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-input-in-form-control) | ||
- [a11y-numbered-text-within-ol](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-numbered-text-within-ol) | ||
- [a11y-prohibit-input-maxlength-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-prohibit-input-maxlength-attribute) | ||
- [a11y-prohibit-input-placeholder](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-prohibit-input-placeholder) | ||
- [a11y-prohibit-sectioning-content-in-form](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-prohibit-sectioning-content-in-form) | ||
- [a11y-prohibit-useless-sectioning-fragment](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-prohibit-useless-sectioning-fragment) | ||
- [a11y-replace-unreadable-symbol](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-replace-unreadable-symbol) | ||
- [a11y-required-layout-as-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-required-layout-as-attribute) | ||
- [a11y-trigger-has-button](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/a11y-trigger-has-button) | ||
- [best-practice-for-button-element](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-button-element) | ||
- [best-practice-for-data-test-attribute](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-data-test-attribute) | ||
- [best-practice-for-date](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-date) | ||
- [best-practice-for-layouts](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-layouts) | ||
- [best-practice-for-remote-trigger-dialog](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/best-practice-for-remote-trigger-dialog) | ||
- [design-system-guideline-prohibit-double-icons](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/design-system-guideline-prohibit-double-icons) | ||
- [format-import-path](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/format-import-path) | ||
- [format-translate-component](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/format-translate-component) | ||
- [jsx-start-with-spread-attributes](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/jsx-start-with-spread-attributes) | ||
- [no-import-other-domain](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/no-import-other-domain) | ||
- [prohibit-export-array-type](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/prohibit-export-array-type) | ||
- [prohibit-file-name](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/prohibit-file-name) | ||
- [prohibit-import](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/prohibit-import) | ||
- [prohibit-path-within-template-literal](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/prohibit-path-within-template-literal) | ||
- [require-barrel-import](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/require-barrel-import) | ||
- [require-declaration](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/require-declaration) | ||
- [require-export](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/require-export) | ||
- [require-import](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/require-import) | ||
- [trim-props](https://github.com/kufu/tamatebako/tree/master/packages/eslint-plugin-smarthr/rules/trim-props) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const rules = generateRulesMap(); | ||
|
||
/** | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
module.exports = { | ||
name: 'eslint-plugin-smarthr', | ||
rules, | ||
plugins: { | ||
recommended: generateRecommendedConfig(rules), | ||
} | ||
} | ||
|
||
function generateRulesMap() { | ||
let rulesPath = path.join(__dirname, 'rules'); | ||
let dirs = fs.readdirSync(rulesPath); | ||
|
||
let rulesMap = {}; | ||
for (let dir of dirs) { | ||
rulesMap[path.parse(dir).name] = require(`./rules/${dir}`); | ||
} | ||
return rulesMap; | ||
} | ||
|
||
function generateRecommendedConfig(rules) { | ||
let config = { | ||
name: 'eslint-plugin-smarthr/recommended', | ||
rules: {}, | ||
}; | ||
|
||
for (let ruleName of Object.keys(rules)) { | ||
config.rules[`smarthr/${ruleName}`] = 'off'; | ||
} | ||
|
||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js'], | ||
testMatch: ['**/test/**/*.+(js)'], | ||
roots: ['<rootDir>/'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const JSON5 = require('json5') | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const replacePaths = (() => { | ||
const cwd = process.cwd() | ||
const eslintrc = (() => { | ||
let file = `${cwd}/.eslintrc.js` | ||
if (fs.existsSync(file)) { | ||
return require(file) | ||
} | ||
|
||
file = `${cwd}/.eslintrc` | ||
|
||
if (fs.existsSync(file)) { | ||
return JSON5.parse(fs.readFileSync(file)) | ||
} | ||
|
||
return {} | ||
})() | ||
|
||
const tsconfigFile = `${cwd}/${eslintrc.parserOptions?.project || 'tsconfig.json'}` | ||
|
||
if (!fs.existsSync(tsconfigFile)) { | ||
throw new Error(`${tsconfigFile} を設置してください`) | ||
} | ||
|
||
const { compilerOptions } = JSON5.parse(fs.readFileSync(tsconfigFile)) | ||
|
||
if (!compilerOptions || !compilerOptions.paths) { | ||
throw new Error('tsconfig.json の compilerOptions.paths に `"@/*": ["any_path/*"]` 形式でフロントエンドのroot dir を指定してください') | ||
} | ||
|
||
const regexp = /\*$/ | ||
return Object.entries(compilerOptions.paths).reduce((prev, [key, values]) => { | ||
return { | ||
...prev, | ||
[key.replace(regexp, '')]: values.map((v) => v.replace(regexp, '')), | ||
} | ||
}, {}) | ||
})() | ||
|
||
const rootPath = (() => { | ||
if (!replacePaths) { | ||
return '' | ||
} | ||
|
||
const p = (replacePaths['@/'] || replacePaths['~/'] || [])[0] | ||
|
||
if (!p) { | ||
return '' | ||
} | ||
|
||
return path.resolve(`${process.cwd()}/${p.replace(/\/\*$/, '')}`) | ||
})() | ||
|
||
module.exports = { replacePaths, rootPath } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const { replacePaths, rootPath } = require('./common') | ||
|
||
const BASE_SCHEMA_PROPERTIES = { | ||
globalModuleDir: { type: 'array', items: { type: 'string' } }, | ||
domainModuleDir: { type: 'array', items: { type: 'string' }, default: [] }, | ||
domainConstituteDir: { type: 'array', items: { type: 'string' } }, | ||
} | ||
|
||
const calculateDomainContext = (context) => { | ||
if (!rootPath) { | ||
throw new Error('tsconfig.json の compilerOptions.paths に `"@/*": ["any_path/*"]` 形式でフロントエンドのroot dir を指定してください') | ||
} | ||
|
||
const filename = context.getFilename() | ||
const parentDir = (() => { | ||
const dir = filename.split('/') | ||
dir.pop() | ||
return dir.join('/') | ||
})() | ||
const humanizeParentDir = parentDir.replace(new RegExp(`^${rootPath}/(.+)$`), '$1') | ||
|
||
return { | ||
option: context.options[0], | ||
parentDir, | ||
filename, | ||
humanizeParentDir, | ||
isTarget: humanizeParentDir !== parentDir, | ||
} | ||
} | ||
|
||
const calculateDomainNode = (calclatedContext, node) => { | ||
const importPath = node.source.value | ||
const { option, parentDir, humanizeParentDir } = calclatedContext | ||
|
||
let replacedPath = importPath | ||
|
||
if (replacePaths) { | ||
const exts = ['.ts', '.tsx', '.js', '.jsx', ''] | ||
|
||
replacedPath = Object.entries(replacePaths).reduce((prev, [key, values]) => { | ||
if (replacedPath === prev) { | ||
const regexp = new RegExp(`^${key}(.+)$`) | ||
const matcher = prev.match(regexp) | ||
if (matcher) { | ||
return values.reduce((p, v) => { | ||
if (prev === p) { | ||
const id = p.replace(regexp, `${path.resolve(`${process.cwd()}/${v}`)}/$1`) | ||
|
||
return exts.map((j) => `${id}${j}`).find((j) => fs.existsSync(j)) || p | ||
} | ||
|
||
return p | ||
}, prev) | ||
} | ||
} | ||
|
||
return prev | ||
}, replacedPath) | ||
|
||
if (replacedPath[0] === '.') { | ||
replacedPath = path.resolve(`${parentDir}/${replacedPath}`) | ||
} | ||
if (!replacedPath.match(/\.[a-z0-9]+$/)) { | ||
replacedPath = exts.map((j) => `${replacedPath}${j}`).find((j) => fs.existsSync(j)) || replacedPath | ||
} | ||
|
||
replacedPath = replacedPath.replace(/^(.+?)((\/index)?\.[a-z0-9]+|\/)$/, '$1') | ||
} | ||
|
||
const resolvedImportPath = replacedPath[0] === '/' ? replacedPath : '' | ||
|
||
let isGlobalModuleImport = false | ||
if ( | ||
!resolvedImportPath || | ||
option.globalModuleDir && | ||
option.globalModuleDir.some((global) => | ||
!!resolvedImportPath.match(new RegExp(`^${path.resolve(`${process.cwd()}/${global}`)}`)) | ||
) | ||
) { | ||
isGlobalModuleImport = true | ||
} | ||
|
||
const humanizeImportPath = resolvedImportPath.replace(new RegExp(`^${rootPath}/(.+)$`), '$1') | ||
let dirs = humanizeParentDir.split('/') | ||
let paths = humanizeImportPath.split('/') | ||
let filteredDirs = dirs | ||
let filteredPaths = paths | ||
|
||
const deductedNames = [] | ||
const recursiveDeductionEq = () => { | ||
if (dirs.length === 0 || paths.length === 0) { | ||
return | ||
} | ||
|
||
if (dirs[0] === paths[0]) { | ||
deductedNames.push(dirs.shift()) | ||
paths.shift() | ||
recursiveDeductionEq() | ||
} | ||
} | ||
recursiveDeductionEq() | ||
filteredDirs = dirs | ||
filteredPaths = paths | ||
|
||
let isDomainConstitute = false | ||
|
||
if (option.domainConstituteDir) { | ||
const { domainConstituteDir } = option | ||
isDomainConstitute = | ||
!!deductedNames.find((d) => domainConstituteDir.includes(d)) || // 同一dirを削り、その中にconstitute dir があれば同一ドメイン | ||
domainConstituteDir.includes(dirs[0]) && domainConstituteDir.includes(paths[0]) // 同一を削りきった先頭が両方constitute dirならば同一ドメイン | ||
|
||
// HINT: 同一ドメイン内(例: workflows/index)で定形で利用されるディレクトリ名を省くことで | ||
// ドメインの識別に利用される文字を抽出する | ||
dirs = dirs.filter((k) => !option.domainConstituteDir.includes(k)) | ||
paths = paths.filter((k) => !option.domainConstituteDir.includes(k)) | ||
} | ||
|
||
const isLowerImport = filteredDirs.length === 0 // 同一階層、もしくは下層からのimport | ||
const isDomainImport = dirs.length === 0 || isDomainConstitute // 同一ドメイン内、もしくは同一階層・下層からのimport | ||
const isModuleImport = paths.length > 0 && option.domainModuleDir.includes(paths[0]) // ドメイン内共通パーツ | ||
|
||
return { | ||
importPath, | ||
humanizeImportPath, | ||
resolvedImportPath, | ||
filteredDirs, | ||
filteredPaths, | ||
dirs, | ||
paths, | ||
isGlobalModuleImport, | ||
isModuleImport, | ||
isDomainImport, | ||
isLowerImport, | ||
} | ||
} | ||
|
||
module.exports = { BASE_SCHEMA_PROPERTIES, calculateDomainContext, calculateDomainNode } |
Oops, something went wrong.