Skip to content

Commit

Permalink
Merge pull request #5 from hiro08gh/chore-increse-file
Browse files Browse the repository at this point in the history
Increase the number of file types supported
  • Loading branch information
hiro08gh authored Dec 29, 2023
2 parents ad8afdd + c2f21c0 commit d887941
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rules/naming-rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import micromatch from 'micromatch';
import { regexCaseMap } from '../utils';
import { regexCaseMap, getFilename } from '../utils';

import { Rule } from 'eslint';

Expand Down Expand Up @@ -91,7 +91,8 @@ export const namingRules: Rule.RuleModule = {
if (targetRule) {
const ext = path.extname(filePath);
const file = path.basename(filePath);
const filename = path.basename(filePath, ext);
const filename = getFilename(path.basename(filePath, ext));

if (index === true && filename === 'index') {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ export const regexCaseMap = {
*/
flat: '+([a-z0-9])',
} as const;

export const getFilename = (filename: string) => {
return filename.indexOf('.') !== -1
? filename.substring(0, filename.indexOf('.'))
: filename;
};
14 changes: 14 additions & 0 deletions test/rules/naming-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ ruleTester.run('naming-rules', namingRules, {
},
],
},
{
code: '',
filename: '/components/App.stories.tsx',
options: [
{
rules: [
{
case: 'pascal',
target: '**/components/**/*.tsx',
},
],
},
],
},
{
code: '',
filename: '/components/_document.tsx',
Expand Down
9 changes: 9 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getFilename } from '../lib/utils';

describe('getFilename', () => {
test('should return filename', () => {
expect(getFilename('App')).toEqual('App');
expect(getFilename('App.stories')).toEqual('App');
expect(getFilename('App.stories.stories')).toEqual('App');
});
});

0 comments on commit d887941

Please sign in to comment.