😇

eslint-plugin-check-fileでglob書くときにつまずいたところ

に公開

ファイルだけでなくディレクトリの命名規則も定義できるので、これをつかっている

https://github.com/dukeluo/eslint-plugin-check-file

hooksを入れているファイルとディレクトリに useXxx の規則を定めたかった

LLMに書かせたら、以下のような正規表現を書いた
'^use[A-Z][a-zA-Z0-9]*$'
だがこれだと、useXxxの命名でもエラーが出るという意図しない動作をした

...
  {
    files: ['src/**/hooks/**/*'],
    plugins: { 'check-file': checkFilePlugin },
    rules: {
      'check-file/folder-naming-convention': [
        'error',
        { 'hooks/*/': '^use[A-Z][a-zA-Z0-9]*$' },
      ],
      'check-file/filename-naming-convention': [
        'error',
        { 'hooks/**/*.{js,jsx,ts,tsx}': '^use[A-Z][a-zA-Z0-9]*$' },
      ],
    },
  },
...

正しくはこうだった様子
'use[A-Z][a-zA-Z0-9]*'
完全一致な書き方ではなかったらしい

...
  {
    files: ['src/**/hooks/**/*'],
    plugins: { 'check-file': checkFilePlugin },
    rules: {
      'check-file/folder-naming-convention': [
        'error',
        { 'hooks/*': 'use[A-Z][a-zA-Z0-9]*' },
      ],
      'check-file/filename-naming-convention': [
        'error',
        { 'hooks/**/*.{js,jsx,ts,tsx}': 'use[A-Z][a-zA-Z0-9]*' },
      ],
    },
  },
...

Discussion