Skip to content

Commit 8a5142f

Browse files
authored
Replace case change functions with change-case (#2648)
1 parent 10ffb8a commit 8a5142f

12 files changed

+15
-615
lines changed

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const config = [
2121
'coverage',
2222
'.cache-eslint-remote-tester',
2323
'eslint-remote-tester-results',
24-
'rules/utils/lodash.js',
2524
'test/integration/{fixtures,fixtures-local}/**',
2625
'workaround-for-eslint-doc-generator',
2726
'**/*.ts',

eslint.dogfooding.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const config = [
2222
'coverage',
2323
'test/integration/fixtures',
2424
'test/integration/fixtures-local',
25-
'rules/utils/lodash.js',
2625
],
2726
},
2827
{

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"node": "^18.20.0 || ^20.10.0 || >=21.0.0"
2121
},
2222
"scripts": {
23-
"bundle-lodash": "echo export {camelCase, kebabCase, snakeCase, upperFirst, lowerFirst} from 'lodash-es'; | npx esbuild --bundle --outfile=rules/utils/lodash.js --format=esm",
2423
"create-rule": "node ./scripts/create-rule.js && npm run create-rules-index-file && npm run fix:eslint-docs",
2524
"create-rules-index-file": "node ./scripts/create-rules-index-file.js",
2625
"fix": "run-p --continue-on-error fix:*",
@@ -60,6 +59,7 @@
6059
"@babel/helper-validator-identifier": "^7.27.1",
6160
"@eslint-community/eslint-utils": "^4.7.0",
6261
"@eslint/plugin-kit": "^0.3.1",
62+
"change-case": "^5.4.4",
6363
"ci-info": "^4.2.0",
6464
"clean-regexp": "^1.0.0",
6565
"core-js-compat": "^3.42.0",
@@ -95,7 +95,6 @@
9595
"eslint-remote-tester-repositories": "^2.0.1",
9696
"espree": "^10.3.0",
9797
"listr2": "^8.3.3",
98-
"lodash-es": "^4.17.21",
9998
"markdownlint-cli": "^0.44.0",
10099
"memoize": "^10.1.0",
101100
"nano-spawn": "^0.2.0",

rules/catch-error-name.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {isRegExp} from 'node:util/types';
22
import {findVariable} from '@eslint-community/eslint-utils';
3-
import {getAvailableVariableName} from './utils/index.js';
3+
import {getAvailableVariableName, upperFirst} from './utils/index.js';
44
import {renameVariable} from './fix/index.js';
55
import {isMethodCall} from './ast/index.js';
66

@@ -47,7 +47,7 @@ const create = context => {
4747
name === expectedName
4848
|| ignore.some(regexp => regexp.test(name))
4949
|| name.endsWith(expectedName)
50-
|| name.endsWith(expectedName.charAt(0).toUpperCase() + expectedName.slice(1));
50+
|| name.endsWith(upperFirst(expectedName));
5151

5252
return {
5353
Identifier(node) {

rules/custom-error-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {upperFirst} from './utils/lodash.js';
1+
import {upperFirst} from './utils/index.js';
22

33
const MESSAGE_ID_INVALID_EXPORT = 'invalidExport';
44
const messages = {

rules/filename-case.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
camelCase,
55
kebabCase,
66
snakeCase,
7-
upperFirst,
8-
} from './utils/lodash.js';
7+
pascalCase,
8+
} from 'change-case';
99
import cartesianProductSamples from './utils/cartesian-product-samples.js';
1010

1111
const MESSAGE_ID = 'filename-case';
@@ -15,35 +15,10 @@ const messages = {
1515
[MESSAGE_ID_EXTENSION]: 'File extension `{{extension}}` is not in lowercase. Rename it to `{{filename}}`.',
1616
};
1717

18-
const pascalCase = string => upperFirst(camelCase(string));
19-
const numberRegex = /\d+/;
20-
const PLACEHOLDER = '\uFFFF\uFFFF\uFFFF';
21-
const PLACEHOLDER_REGEX = new RegExp(PLACEHOLDER, 'i');
2218
const isIgnoredChar = char => !/^[a-z\d-_]$/i.test(char);
2319
const ignoredByDefault = new Set(['index.js', 'index.mjs', 'index.cjs', 'index.ts', 'index.tsx', 'index.vue']);
2420
const isLowerCase = string => string === string.toLowerCase();
2521

26-
function ignoreNumbers(caseFunction) {
27-
return string => {
28-
const stack = [];
29-
let execResult = numberRegex.exec(string);
30-
31-
while (execResult) {
32-
stack.push(execResult[0]);
33-
string = string.replace(execResult[0], PLACEHOLDER);
34-
execResult = numberRegex.exec(string);
35-
}
36-
37-
let withCase = caseFunction(string);
38-
39-
while (stack.length > 0) {
40-
withCase = withCase.replace(PLACEHOLDER_REGEX, stack.shift());
41-
}
42-
43-
return withCase;
44-
};
45-
}
46-
4722
const cases = {
4823
camelCase: {
4924
fn: camelCase,
@@ -172,7 +147,7 @@ const create = context => {
172147
return new RegExp(item, 'u');
173148
});
174149
const multipleFileExtensions = options.multipleFileExtensions !== false;
175-
const chosenCasesFunctions = chosenCases.map(case_ => ignoreNumbers(cases[case_].fn));
150+
const chosenCasesFunctions = chosenCases.map(case_ => cases[case_].fn);
176151
const filenameWithExtension = context.physicalFilename;
177152

178153
if (filenameWithExtension === '<input>' || filenameWithExtension === '<text>') {

rules/no-anonymous-default-export.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import path from 'node:path';
22
import {getFunctionHeadLocation, getFunctionNameWithKind, isOpeningParenToken} from '@eslint-community/eslint-utils';
33
import helperValidatorIdentifier from '@babel/helper-validator-identifier';
4+
import {camelCase} from 'change-case';
45
import getClassHeadLocation from './utils/get-class-head-location.js';
5-
import {upperFirst, camelCase} from './utils/lodash.js';
66
import {getParenthesizedRange} from './utils/parentheses.js';
7-
import {getScopes, getAvailableVariableName} from './utils/index.js';
7+
import {getScopes, getAvailableVariableName, upperFirst} from './utils/index.js';
88
import {isMemberExpression} from './ast/index.js';
99

1010
const {isIdentifierName} = helperValidatorIdentifier;

rules/no-unnecessary-polyfills.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path';
22
import coreJsCompat from 'core-js-compat';
3-
import {camelCase} from './utils/lodash.js';
3+
import {camelCase} from 'change-case';
44
import isStaticRequire from './ast/is-static-require.js';
55
import {readPackageJson} from './shared/package-json.js';
66

rules/prevent-abbreviations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import path from 'node:path';
22
import {isRegExp} from 'node:util/types';
3-
import {upperFirst, lowerFirst} from './utils/lodash.js';
43
import {
54
getAvailableVariableName,
65
cartesianProductSamples,
76
isShorthandPropertyValue,
87
isShorthandImportLocal,
98
getVariableIdentifiers,
109
getScopes,
10+
upperFirst,
11+
lowerFirst,
1112
} from './utils/index.js';
1213
import {defaultReplacements, defaultAllowList, defaultIgnore} from './shared/abbreviations.js';
1314
import {renameVariable} from './fix/index.js';

rules/utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ export {default as shouldAddParenthesesToMemberExpressionObject} from './should-
5252
export {default as singular} from './singular.js';
5353
export {default as toLocation} from './to-location.js';
5454
export {default as getAncestor} from './get-ancestor.js';
55+
export * from './string-cases.js';

0 commit comments

Comments
 (0)