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

ESLint #168

Merged
merged 26 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e9e9f78
chore: yet more turborepo configuration
lishaduck Jun 23, 2024
b6d9f8f
style: apply suggestion from code review
lishaduck Jun 22, 2024
15ce2db
chore: remove xo configuration from package.json
lishaduck Jun 22, 2024
2140263
chore: switch to `eslint-plugin-n`
lishaduck Jun 22, 2024
4279542
chore: add `eslint-plugin-security`
lishaduck Jun 22, 2024
569f39c
style: use `node:` protocol
lishaduck Jun 22, 2024
aecd86f
fix: bump minimum node version
lishaduck Jun 22, 2024
811d0e4
chore: add back `eslint-plugin-promise`
lishaduck Jun 22, 2024
186dbed
style: ban nesting promises
lishaduck Jun 23, 2024
b9e2a1d
chore: make prettier ignore snapshots
lishaduck Jun 22, 2024
646ac00
chore: clean up `fs-wrapper.js`
lishaduck Jun 22, 2024
6a3bdae
chore: use `await` rather than callbacks
lishaduck Jun 22, 2024
1dee1ad
style: clean up async in `build.js`
lishaduck Jun 22, 2024
616adbf
chore: add `eslint-plugin-eslint-comments`
lishaduck Jun 22, 2024
f52bca4
chore: add expiring todo comments
lishaduck Jun 22, 2024
bf62da0
chore: upgrade @typescript-eslint to v6
lishaduck Jun 23, 2024
ea8b9c5
chore: manually verify eslint-plugin-json-files
lishaduck Jun 23, 2024
71f1593
style: return await
lishaduck Jun 23, 2024
21c2921
style: const
lishaduck Jun 23, 2024
e97b049
chore: update lints
lishaduck Jun 23, 2024
93bf1fb
chore: use natively promisified fs.stat
lishaduck Jun 23, 2024
94ffc5c
fix: types
lishaduck Jun 23, 2024
2e7a0be
chore: yet stricter tsconfig
lishaduck Jun 23, 2024
aff0c7a
chore: use strict
lishaduck Jun 23, 2024
1f8c1e2
style: recommended unicorn
lishaduck Jun 23, 2024
9dec6b7
ci: let commands finish
lishaduck Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 80 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
// TODO [eslint@>9.5]: Use `.ts` extension to get more type checking for this file.
// TODO [engine:node@>=18]: Upgrade `tseslint`.
// TODO [engine:node@>=18]: Use `eslint-define-config` to get type checking for this file.
// TODO [engine:node@>=18]: Use `eslint-plugin-jsdoc` to get JSDoc linting.

module.exports = {
root: true,
extends: ['xo', 'turbo', 'prettier', 'plugin:@typescript-eslint/recommended'],
plugins: ['node', 'unicorn', '@typescript-eslint'],
extends: [
'xo', // Should we also use eslint-config-xo-typescript?
'turbo',
'plugin:n/recommended',
'plugin:security/recommended-legacy',
'plugin:@eslint-community/eslint-comments/recommended',
'plugin:promise/recommended',
'plugin:unicorn/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier'
],
plugins: ['n', 'security', 'promise', 'unicorn', '@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname
EXPERIMENTAL_useProjectService: true
},
env: {
node: true
Expand All @@ -16,37 +31,90 @@ module.exports = {
'test/run-snapshots',
'test/snapshots',
'test/temporary',
'vendor/node-elm-compiler.js',
'vendor/exit.js',
'vendor/',
'.eslintrc.js',
'new-package/elm-review-package-tests/check-previews-compile.js'
],
rules: {
// Style disagreements with XO.
complexity: 'off',
'import/extensions': 'off',
indent: 'off',
'comma-dangle': 'off',
curly: 'off',
quotes: 'off',
'arrow-body-style': 'off',
'prettier/prettier': 'off',
'object-shorthand': 'off',
'operator-linebreak': 'off',
'max-params': 'off',
'arrow-parens': 'off',
'no-warning-comments': 'off',
'prefer-const': 'off',
'promise/no-nesting': 'warn',
'promise/no-return-in-finally': 'error',
'promise/valid-params': 'error',
'promise/prefer-await-to-callbacks': 'warn',
'promise/prefer-await-to-then': 'off',
'unicorn/no-fn-reference-in-iterator': 'off',
'unicorn/no-reduce': 'off',
'no-return-await': 'off',
'@typescript-eslint/return-await': ['error', 'always'],
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-node-protocol': 'off',
'unicorn/prefer-node-protocol': 'error',
'unicorn/expiring-todo-comments': 'warn',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'default-case': 'off'
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'default-case': 'off',
'n/shebang': 'off', // TODO [eslint-plugin-n@>=17]: Turn on 'n/hashbang'. For now, `shebang` is buggy.
'@eslint-community/eslint-comments/require-description': 'error',
strict: ['error', 'global'],
'unicorn/import-style': [
'error',
{
styles: {
chalk: {
named: true
}
}
}
],
'unicorn/no-null': 'off',
'unicorn/prevent-abbreviations': 'off',

// TODO: Once there are no more `any`s, start enforcing these rules.
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',

// TODO: Enable stricter promise rules.
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'promise/catch-or-return': 'off',
'promise/always-return': 'off',

// TODO: Security issues that should eventually get fixed.
'security/detect-object-injection': 'off',
'security/detect-non-literal-fs-filename': 'off',
'security/detect-non-literal-require': 'off',
'security/detect-unsafe-regex': 'off', // TODO: Add `eslint-plugin-regexp` and fix these issues.

// TODO: Enable rules that require newer versions of Node.js when we bump the minimum version.
'unicorn/prefer-string-replace-all': 'off', // TODO [engine:node@>=15]: Enable this rule.
'unicorn/prefer-at': 'off' // TODO [engine:node@>=16.6]: Enable this rule.
},
overrides: [
{
files: ['./new-package/**/*.js'],
rules: {
'n/no-process-exit': 'off',
'@typescript-eslint/unbound-method': 'off' // TODO: Fix this warning. @lishaduck just got confused.
}
}
],
globals: {
test: 'readonly',
expect: 'readonly'
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
**/suppressed
test/**/*.json
test/temporary/
test/run-snapshots/
vendor/exit.js
.turbo
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,5 @@ module.exports = {
// Whether to use watchman for file crawling
// watchman: true,

testTimeout: 30000
testTimeout: 30_000
};
2 changes: 1 addition & 1 deletion lib/anonymize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ so that the CLI tests (in the `test/` folder) have the same output on different
machines, and also the same output when only the CLI version changes.
*/

const path = require('path');
const path = require('node:path');

/**
* @import {Options} from "./types/options"
Expand Down
8 changes: 5 additions & 3 deletions lib/app-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path');
const path = require('node:path');
const ElmCommunication = require('./elm-communication');
const loadCompiledElmApp = require('./load-compiled-app');

const {Worker} = require('worker_threads');
const {Worker} = require('node:worker_threads');

module.exports = {
init: (options, elmModulePath, flags) => init(options, elmModulePath, flags),
Expand Down Expand Up @@ -49,7 +49,7 @@ function initWithWorker(elmModulePath, flags) {

worker.on('message', ([port, data]) => {
if (listeners[port]) {
listeners[port].forEach((fn) => fn(data));
for (const fn of listeners[port]) fn(data);
}
});

Expand All @@ -67,12 +67,14 @@ function send(port) {
}

function subscribe(port) {
// eslint-disable-next-line promise/prefer-await-to-callbacks -- Callbacks are still needed here.
return (callback) => {
listeners[port].push(callback);
};
}

function unsubscribe(port) {
// eslint-disable-next-line promise/prefer-await-to-callbacks -- Callbacks are still needed here.
return (callback) => {
listeners[port] = listeners[port].filter((fn) => fn === callback);
};
Expand Down
52 changes: 27 additions & 25 deletions lib/autofix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const chalk = require('chalk');
const prompts = require('prompts');
const spawn = require('cross-spawn');
Expand Down Expand Up @@ -78,16 +78,7 @@ function askConfirmationToFixWithOptions(options, app, elmVersion) {
return;
}

const accepted =
options.fixAllWithoutPrompt ||
(
await prompts({
type: 'confirm',
name: 'accepted',
message,
initial: true
})
).accepted;
const accepted = options.fixAllWithoutPrompt || (await confirmFix(message));

if (accepted === undefined) {
// User interrupted the process using Ctrl-C
Expand Down Expand Up @@ -152,6 +143,21 @@ function askConfirmationToFixWithOptions(options, app, elmVersion) {
};
}

/**
* @param {string} message
* @returns {Promise<boolean>}
*/
async function confirmFix(message) {
const prompt = await prompts({
type: 'confirm',
name: 'accepted',
message,
initial: true
});

return prompt.accepted;
}

function checkIfAFixConfirmationIsStillExpected(app) {
return promisifyPort({
subscribeTo: app.ports.fixConfirmationStatus,
Expand All @@ -170,7 +176,7 @@ function checkIfAFixConfirmationIsStillExpected(app) {
*/
function formatFileContent(options, file, filePath) {
const hasElmFormatPathFlag = Boolean(options.elmFormatPath);
const elmFormatPath = options.elmFormatPath || 'elm-format';
const elmFormatPath = options.elmFormatPath ?? 'elm-format';

const result = spawn.sync(
elmFormatPath,
Expand All @@ -188,22 +194,18 @@ function formatFileContent(options, file, filePath) {
if (hasElmFormatPathFlag) {
throw new ErrorMessage.CustomError(
'ELM-FORMAT NOT FOUND',
// prettier-ignore
`I could not find the executable for ${chalk.magentaBright('elm-format')} at the location you specified:

${options.elmFormatPath}`,
options.elmJsonPath
);
} else {
throw new ErrorMessage.CustomError(
'ELM-FORMAT NOT FOUND',
// prettier-ignore
`I could not find the executable for ${chalk.magentaBright('elm-format')}.
hasElmFormatPathFlag
? `I could not find the executable for ${chalk.magentaBright('elm-format')} at the location you specified:

${options.elmFormatPath}`
: `I could not find the executable for ${chalk.magentaBright('elm-format')}.

A few options:
- Install it globally
- Add it to your project through \`npm\`
- Specify the path using ${chalk.cyan('--elm-format-path <path-to-elm-format>')}`,
- Install it globally.
- Add it to your project through \`npm\`.
- Specify the path using ${chalk.cyan('--elm-format-path <path-to-elm-format>')}.`,
options.elmJsonPath
);
}
Expand Down
Loading