Skip to content

Commit

Permalink
feat: improving eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
jpapini committed Jun 25, 2024
1 parent 3feb076 commit 1460e0e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/small-ads-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@jpapini/eslint-config': minor
'@jpapini/jest-config': minor
---

Improving ESLint config.
6 changes: 6 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config = {
curly: ['error', 'multi-or-nest', 'consistent'],
// Require template literals instead of string concatenation.
'prefer-template': 'error',
quotes: ['error', 'single', { avoidEscape: true, allowTemplateLiterals: false }],

// Enforces `node:` prefix. (Example: `import fs from 'node:fs';`)
'unicorn/prefer-node-protocol': 'error',
Expand Down Expand Up @@ -150,6 +151,11 @@ const config = {
format: ['camelCase'],
leadingUnderscore: 'require',
},
{
selector: ['interface', 'typeAlias'],
format: ['PascalCase'],
prefix: ['I'],
},
],
},
},
Expand Down
20 changes: 20 additions & 0 deletions packages/eslint-config/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,26 @@ const config = {
],
},
},
{
files: ['**/*.tsx'],
rules: {
// Enforces naming conventions for everything across a codebase.
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeParameter',
format: ['PascalCase'],
prefix: ['T', 'K', 'U', 'V'],
},
{
selector: ['method', 'parameterProperty', 'property'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
],
},
},
],
};

Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/paths-to-module-name-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Config } from '@jest/types';
import type { CompilerOptions } from 'typescript';

type TsPathMapping = Exclude<CompilerOptions['paths'], undefined>;
type JestPathMapping = Config.InitialOptions['moduleNameMapper'];
type ITsPathMapping = Exclude<CompilerOptions['paths'], undefined>;
type IJestPathMapping = Config.InitialOptions['moduleNameMapper'];

const escapeRegex = (str: string) => str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');

export const pathsToModuleNameMapper = (
mapping: TsPathMapping,
mapping: ITsPathMapping,
{ prefix = '', useESM = false }: { prefix?: string; useESM?: boolean } = {},
): JestPathMapping => {
const jestMap: JestPathMapping = {};
): IJestPathMapping => {
const jestMap: IJestPathMapping = {};
for (const fromPath of Object.keys(mapping)) {
const toPaths = mapping[fromPath]!;
if (toPaths.length === 0) continue;
Expand Down

0 comments on commit 1460e0e

Please sign in to comment.