mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 01:28:38 +02:00
chore: clean up ESLint config, enable a few rules (#6514)
* chore: clean up ESLint config, enable a few rules * enable max-len for comments * fix build
This commit is contained in:
parent
b8ccb869f1
commit
aa446b7a9c
167 changed files with 1157 additions and 960 deletions
|
@ -9,7 +9,8 @@
|
|||
|
||||
import path from 'path';
|
||||
|
||||
// MacOS (APFS) and Windows (NTFS) filename length limit = 255 chars, Others = 255 bytes
|
||||
// MacOS (APFS) and Windows (NTFS) filename length limit = 255 chars,
|
||||
// Others = 255 bytes
|
||||
const MAX_PATH_SEGMENT_CHARS = 255;
|
||||
const MAX_PATH_SEGMENT_BYTES = 255;
|
||||
// Space for appending things to the string like file extensions and so on
|
||||
|
@ -19,7 +20,7 @@ const isMacOs = () => process.platform === 'darwin';
|
|||
const isWindows = () => process.platform === 'win32';
|
||||
|
||||
export const isNameTooLong = (str: string): boolean =>
|
||||
// This is actually not entirely correct: we can't assume FS from OS. But good enough?
|
||||
// Not entirely correct: we can't assume FS from OS. But good enough?
|
||||
isMacOs() || isWindows()
|
||||
? str.length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_CHARS // MacOS (APFS) and Windows (NTFS) filename length limit (255 chars)
|
||||
: Buffer.from(str).length + SPACE_FOR_APPENDING > MAX_PATH_SEGMENT_BYTES; // Other (255 bytes)
|
||||
|
@ -56,7 +57,8 @@ export const shortName = (str: string): string => {
|
|||
export function posixPath(str: string): string {
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
||||
|
||||
// Forward slashes are only valid Windows paths when they don't contain non-ascii characters.
|
||||
// Forward slashes are only valid Windows paths when they don't contain non-
|
||||
// ascii characters.
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const hasNonAscii = /[^\u0000-\u0080]+/.test(str);
|
||||
|
||||
|
@ -66,13 +68,18 @@ export function posixPath(str: string): string {
|
|||
return str.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
// When you want to display a path in a message/warning/error,
|
||||
// it's more convenient to:
|
||||
// - make it relative to cwd()
|
||||
// - convert to posix (ie not using windows \ path separator)
|
||||
// This way, Jest tests can run more reliably on any computer/CI
|
||||
// on both Unix/Windows
|
||||
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough
|
||||
/**
|
||||
* When you want to display a path in a message/warning/error, it's more
|
||||
* convenient to:
|
||||
*
|
||||
* - make it relative to `cwd()`
|
||||
* - convert to posix (ie not using windows \ path separator)
|
||||
*
|
||||
* This way, Jest tests can run more reliably on any computer/CI on both
|
||||
* Unix/Windows
|
||||
* For Windows users this is not perfect (as they see / instead of \) but it's
|
||||
* probably good enough
|
||||
*/
|
||||
export function toMessageRelativeFilePath(filePath: string): string {
|
||||
return posixPath(path.relative(process.cwd(), filePath));
|
||||
}
|
||||
|
@ -92,7 +99,8 @@ export function aliasedSitePath(filePath: string, siteDir: string): string {
|
|||
/**
|
||||
* When you have a path like C:\X\Y
|
||||
* It is not safe to use directly when generating code
|
||||
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
||||
* For example, this would fail due to unescaped \:
|
||||
* `<img src={require('${filePath}')} />`
|
||||
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
||||
*
|
||||
* posixPath can't be used in all cases, because forward slashes are only valid
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue