-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to an insane new eslint setup, linted files
- Loading branch information
1 parent
bd7e9cf
commit e379415
Showing
13 changed files
with
1,400 additions
and
985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import stylistic from '@stylistic/eslint-plugin-js' | ||
import pluginImport from 'eslint-plugin-import' | ||
import perfectionist from 'eslint-plugin-perfectionist' | ||
import prettierConfig from 'eslint-plugin-prettier/recommended' | ||
import is from 'eslint-plugin-simple-import-sort' | ||
import eslintPluginUnicorn from 'eslint-plugin-unicorn' | ||
|
||
export default [ | ||
prettierConfig, | ||
eslintPluginUnicorn.configs['flat/recommended'], | ||
|
||
{ | ||
files: ['**/*.js'], | ||
plugins: { | ||
stylistic, | ||
pluginImport, | ||
'simple-import-sort': is, | ||
perfectionist, | ||
import: pluginImport, | ||
}, | ||
languageOptions: { | ||
ecmaVersion: 2024, | ||
sourceType: 'module', | ||
}, | ||
|
||
rules: { | ||
'simple-import-sort/imports': 'error', | ||
'simple-import-sort/exports': 'error', | ||
|
||
'no-unused-vars': 'warn', | ||
'no-console': 'off', | ||
'unicorn/prefer-top-level-await': 'off', | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
import { promises as fs } from 'node:fs' | ||
import path from 'node:path' | ||
|
||
async function findClosestParentDir(path1, path2) { | ||
// Normalize the paths to eliminate any redundant navigation | ||
const absolutePath1 = path.resolve(path1); | ||
const absolutePath2 = path.resolve(path2); | ||
|
||
// Split paths into components | ||
const parts1 = absolutePath1.split(path.sep); | ||
const parts2 = absolutePath2.split(path.sep); | ||
|
||
// Find common path parts | ||
const length = Math.min(parts1.length, parts2.length); | ||
let i = 0; | ||
while (i < length && parts1[i] === parts2[i]) { | ||
i++; | ||
} | ||
|
||
// If there is no common path, return null | ||
if (i === 0) { | ||
return null; | ||
} | ||
|
||
// Construct the common directory path | ||
const commonPath = parts1.slice(0, i).join(path.sep); | ||
const commonDirName = parts1[i - 1]; | ||
|
||
// Check if the common directory exists | ||
try { | ||
await fs.access(commonPath); | ||
} catch (error) { | ||
throw new Error(`The common directory does not exist: ${commonPath}`); | ||
} | ||
|
||
// Calculate relative paths | ||
const relativePath1 = path.relative(commonPath, absolutePath1); | ||
const relativePath2 = path.relative(commonPath, absolutePath2); | ||
|
||
// Return the result as an object | ||
const obj = { | ||
name: commonDirName, | ||
path: commonPath, | ||
relativePaths: { | ||
a: relativePath1, | ||
b: relativePath2, | ||
}, | ||
}; | ||
return `.../${obj.name}/${obj.relativePaths.a} -> .../${obj.name}/${obj.relativePaths.b}`; | ||
} | ||
const baseLog = async (fpath) => { | ||
// Normalize the paths to eliminate any redundant navigation | ||
const absolutePath1 = path.resolve(path1) | ||
const absolutePath2 = path.resolve(path2) | ||
|
||
// Split paths into components | ||
const parts1 = absolutePath1.split(path.sep) | ||
const parts2 = absolutePath2.split(path.sep) | ||
|
||
// Find common path parts | ||
const length = Math.min(parts1.length, parts2.length) | ||
let index = 0 | ||
while (index < length && parts1[index] === parts2[index]) { | ||
index++ | ||
} | ||
|
||
// If there is no common path, return null | ||
if (index === 0) { | ||
return null | ||
} | ||
|
||
// Construct the common directory path | ||
const commonPath = parts1.slice(0, index).join(path.sep) | ||
const commonDirName = parts1[index - 1] | ||
|
||
// Check if the common directory exists | ||
try { | ||
await fs.access(commonPath) | ||
} catch { | ||
throw new Error(`The common directory does not exist: ${commonPath}`) | ||
} | ||
|
||
// Calculate relative paths | ||
const relativePath1 = path.relative(commonPath, absolutePath1) | ||
const relativePath2 = path.relative(commonPath, absolutePath2) | ||
|
||
// Return the result as an object | ||
const object = { | ||
name: commonDirName, | ||
path: commonPath, | ||
relativePaths: { | ||
a: relativePath1, | ||
b: relativePath2, | ||
}, | ||
} | ||
return `.../${object.name}/${object.relativePaths.a} -> .../${object.name}/${object.relativePaths.b}` | ||
} | ||
const baseLog = async (fpath) => {} | ||
|
||
export {findClosestParentDir, baseLog}; | ||
export { baseLog, findClosestParentDir } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import os from 'os'; | ||
import chalk from 'chalk'; | ||
import fs from 'node:fs' | ||
import os from 'node:os' | ||
import path from 'node:path' | ||
|
||
import chalk from 'chalk' | ||
|
||
// | ||
// Logchanged filenames to disk. not currently used. | ||
// | ||
|
||
|
||
const logDir = path.join(os.homedir(), '.config'); | ||
const logDir = path.join(os.homedir(), '.config') | ||
|
||
// Ensure the log directory exists | ||
if (!fs.existsSync(logDir)) { | ||
fs.mkdirSync(logDir); | ||
fs.mkdirSync(logDir) | ||
} | ||
|
||
function logChanges(arr) { | ||
const currentDate = new Date(); | ||
const logFileName = `${currentDate.toISOString().split('T')[0]}.log`; | ||
const logFilePath = path.join(logDir, logFileName); | ||
function logChanges(array) { | ||
const currentDate = new Date() | ||
const logFileName = `${currentDate.toISOString().split('T')[0]}.log` | ||
const logFilePath = path.join(logDir, logFileName) | ||
|
||
// Write the array and the current date to the log file | ||
const logContent = `Date: ${currentDate.toISOString()}\nData: ${JSON.stringify(arr, null, 2)}\n`; | ||
fs.writeFileSync(logFilePath, logContent); | ||
const logContent = `Date: ${currentDate.toISOString()}\nData: ${JSON.stringify(array, null, 2)}\n` | ||
fs.writeFileSync(logFilePath, logContent) | ||
|
||
// Check for older logs and truncate if there are more than 10 | ||
const logFiles = fs.readdirSync(logDir).filter(file => file.endsWith('.log')).sort(); | ||
const logFiles = fs | ||
.readdirSync(logDir) | ||
.filter((file) => file.endsWith('.log')) | ||
.sort() | ||
while (logFiles.length > 10) { | ||
const oldestLog = logFiles.shift(); | ||
fs.unlinkSync(path.join(logDir, oldestLog)); | ||
const oldestLog = logFiles.shift() | ||
fs.unlinkSync(path.join(logDir, oldestLog)) | ||
} | ||
!global.silent && console.log(chalk.green(`logged changes to ${logFilePath}`)); | ||
!global.silent && | ||
console.log(chalk.green(`logged changes to ${logFilePath}`)) | ||
} | ||
|
||
export default logChanges; | ||
export default logChanges |
Oops, something went wrong.