Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ESLint bugs that required ts-specific rules for js functions and added prettier formatting (re-open #3184) #3229

Merged
4 changes: 1 addition & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##############################################################################

Check warning on line 1 in .github/workflows/pull-request.yml

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
##############################################################################
#
# NOTE!
Expand Down Expand Up @@ -65,9 +65,7 @@
run: npm run check-tsdoc # Run the TSDoc check script

- name: Check for localStorage Usage
run: |
chmod +x scripts/githooks/check-localstorage-usage.js
node scripts/githooks/check-localstorage-usage.js --scan-entire-repo
run: npx tsx scripts/githooks/check-localstorage-usage.ts --scan-entire-repo

- name: Compare translation files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{

Check warning on line 1 in .lintstagedrc.json

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
"**/*.{ts,tsx,yml}": "eslint --fix",
"**/*.{ts,tsx,json,scss,css,yml}": "prettier --write",
"**/*.{ts,tsx}": "node scripts/githooks/check-localstorage-usage.js"
"**/*.{ts,tsx}": "npx tsx scripts/githooks/check-localstorage-usage.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"update:toc": "node scripts/githooks/update-toc.js",
"lint-staged": "lint-staged --concurrent false",
"setup": "tsx setup.ts",
"check-localstorage": "node scripts/githooks/check-localstorage-usage.js",
"check-localstorage": "tsx scripts/githooks/check-localstorage-usage.ts",
"postgenerate-docs": "find docs/docs/auto-docs -name 'README.md' -delete && node fix-repo-url.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix cross-platform compatibility issue in postgenerate-docs script.

The find command is Unix-specific and won't work on Windows environments. Consider using a cross-platform solution.

Replace with a cross-platform Node.js solution:

-    "postgenerate-docs": "find docs/docs/auto-docs -name 'README.md' -delete && node fix-repo-url.js",
+    "postgenerate-docs": "node -e \"require('fs').readdirSync('docs/docs/auto-docs').forEach(f => { if(f === 'README.md') require('fs').unlinkSync('docs/docs/auto-docs/' + f)}); \" && node fix-repo-url.js",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"postgenerate-docs": "find docs/docs/auto-docs -name 'README.md' -delete && node fix-repo-url.js",
"postgenerate-docs": "node -e \"require('fs').readdirSync('docs/docs/auto-docs').forEach(f => { if(f === 'README.md') require('fs').unlinkSync('docs/docs/auto-docs/' + f)}); \" && node fix-repo-url.js",

"generate-docs": "typedoc && npm run postgenerate-docs && node fix-readme-links.js"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,49 @@
import { readFileSync, existsSync } from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import type { ExecSyncOptionsWithStringEncoding } from 'child_process';

const args = process.argv.slice(2);
const scanEntireRepo = args.includes('--scan-entire-repo');
const args: string[] = process.argv.slice(2);
const scanEntireRepo: boolean = args.includes('--scan-entire-repo');

Check warning on line 9 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L8-L9

Added lines #L8 - L9 were not covered by tests

const containsSkipComment = (file) => {
const containsSkipComment = (file: string): boolean => {

Check warning on line 11 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L11

Added line #L11 was not covered by tests
try {
const content = readFileSync(file, 'utf-8');
return content.includes('// SKIP_LOCALSTORAGE_CHECK');
} catch (error) {
console.error(`Error reading file ${file}:`, error.message);
console.error(

Check warning on line 16 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L16

Added line #L16 was not covered by tests
`Error reading file ${file}:`,
error instanceof Error ? error.message : error,
);
return false;
}
};

const getModifiedFiles = () => {
const getModifiedFiles = (): string[] => {

Check warning on line 24 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L24

Added line #L24 was not covered by tests
try {
const options: ExecSyncOptionsWithStringEncoding = { encoding: 'utf-8' };

Check warning on line 26 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L26

Added line #L26 was not covered by tests

if (scanEntireRepo) {
const result = execSync('git ls-files | grep ".tsx\\?$"', {
encoding: 'utf-8',
});
const result = execSync('git ls-files | grep ".tsx\\?$"', options);

Check warning on line 29 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L29

Added line #L29 was not covered by tests
return result.trim().split('\n');
}

const result = execSync('git diff --cached --name-only', {
encoding: 'utf-8',
});
const result = execSync('git diff --cached --name-only', options);

Check warning on line 33 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L33

Added line #L33 was not covered by tests
return result.trim().split('\n');
} catch (error) {
console.error('Error fetching modified files:', error.message);
console.error(

Check warning on line 36 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L36

Added line #L36 was not covered by tests
'Error fetching modified files:',
error instanceof Error ? error.message : error,
);
process.exit(1);
}
return [];

Check warning on line 42 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L42

Added line #L42 was not covered by tests
};

const files = getModifiedFiles();

const filesWithLocalStorage = [];
const files: string[] = getModifiedFiles();
const filesWithLocalStorage: string[] = [];

Check warning on line 46 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L45-L46

Added lines #L45 - L46 were not covered by tests

const checkLocalStorageUsage = (file) => {
const checkLocalStorageUsage = (file: string): void => {

Check warning on line 48 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L48

Added line #L48 was not covered by tests
if (!file) {
return;
}
Expand All @@ -49,7 +54,7 @@

// Skip files with specific names or containing a skip comment
if (
fileName === 'check-localstorage-usage.js' ||
fileName === 'check-localstorage-usage.ts' || // Updated extension
fileName === 'useLocalstorage.test.ts' ||
fileName === 'useLocalstorage.ts' ||
containsSkipComment(file)
Expand All @@ -73,7 +78,10 @@
console.log(`File ${file} does not exist.`);
}
} catch (error) {
console.error(`Error reading file ${file}:`, error.message);
console.error(

Check warning on line 81 in scripts/githooks/check-localstorage-usage.ts

View check run for this annotation

Codecov / codecov/patch

scripts/githooks/check-localstorage-usage.ts#L81

Added line #L81 was not covered by tests
`Error reading file ${file}:`,
error instanceof Error ? error.message : error,
);
}
};

Expand All @@ -86,10 +94,10 @@

console.info(
'\x1b[34m%s\x1b[0m',
'\nInfo: Consider using custom hook functions.'
'\nInfo: Consider using custom hook functions.',
);
console.info(
'Please use the getItem, setItem, and removeItem functions provided by the custom hook useLocalStorage.\n'
'Please use the getItem, setItem, and removeItem functions provided by the custom hook useLocalStorage.\n',
);

process.exit(1);
Expand Down
Loading