forked from azat-io/eslint-plugin-perfectionist
-
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.
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
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,38 @@ | ||
--- | ||
title: no-rush | ||
description: No rush | ||
--- | ||
|
||
<script setup lang="ts"> | ||
import CodeEditor from '../../.vitepress/theme/components/code-editor.vue'; | ||
import {ruleName, presetConfigs, initialText, fakeLint} from '../../src/sample-code/no-rush.js'; | ||
</script> | ||
|
||
> "Sometimes, the most productive thing you can do is wait." - Unknown | ||
# Enforce a delay (`dont/no-rush`) | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## 📖 Rule details | ||
|
||
Slowing down can sometimes lead to more thoughtful and considered decisions, ensuring you're not rushing through | ||
critical processes or checks. | ||
|
||
## ⚙️ Options | ||
|
||
### delay | ||
|
||
Time to wait, in seconds. | ||
|
||
## 🔧 Config | ||
|
||
```js | ||
// wait 10 seconds | ||
{ rules: {'dont/no-rush': [2, { delay: 10 }] } } | ||
``` | ||
|
||
|
||
## 🧑💻 Demo | ||
|
||
<CodeEditor :rule="ruleName" :text="initialText" :presetConfigs="presetConfigs" /> |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { RuleListener } from '../utils/eslint-types/Rule.js' | ||
|
||
import { createEslintRule } from '../utils/create-eslint-rule.js' | ||
import { sleepSync } from '../utils/sleep-sync.js' | ||
import { complete } from '../utils/complete.js' | ||
import { RuleContext } from '../utils/eslint-types/Rule.js' | ||
|
||
type MESSAGE_ID = 'no-rush' | ||
|
||
type Options = [Partial<{ delay: number }>] | ||
|
||
export const RULE_NAME = 'no-rush' | ||
|
||
type Context = RuleContext<MESSAGE_ID, Options> | ||
|
||
export default createEslintRule<Options, MESSAGE_ID>({ | ||
name: RULE_NAME, | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'enforce a delay', | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
delay: { | ||
type: 'number', | ||
default: 10, | ||
}, | ||
}, | ||
}, | ||
], | ||
messages: { | ||
'no-rush': 'no-rush', | ||
}, | ||
}, | ||
defaultOptions: [ | ||
{ | ||
delay: 10, | ||
}, | ||
], | ||
create: (context: Context): RuleListener => { | ||
const options = complete(context.options.at(0), { | ||
delay: 10, | ||
}) | ||
return { | ||
Program: () => sleepSync(options.delay * 1000), | ||
} | ||
}, | ||
}) |
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,23 @@ | ||
import type { PresetConfig } from './presets.js' | ||
|
||
export const ruleName = 'no-rush' | ||
|
||
export const presetConfigs = [] satisfies PresetConfig[] | ||
|
||
export const initialText = `console.log('Hello') | ||
` | ||
|
||
const sleep = (delayMs: number) => | ||
new Promise(resolve => setTimeout(resolve, delayMs)) | ||
|
||
export const fakeLint = async (code: string, { delay }: { delay?: number }) => { | ||
delay && delay > 0 && (await sleep(delay / 1000)) | ||
return { | ||
fix: { | ||
fixed: false, | ||
messages: [], | ||
output: code, | ||
}, | ||
verify: [], | ||
} | ||
} |
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,12 @@ | ||
import fs from 'node:fs' | ||
import * as uuid from 'uuid' | ||
|
||
/** | ||
* Tie up execution for at-least the given number of millis. This is not efficient. | ||
* @param millis Min number of millis to wait | ||
*/ | ||
export const sleepSync = (millis: number) => { | ||
if (millis <= 0) return | ||
const proceedAt = Date.now() + millis | ||
while (Date.now() < proceedAt) fs.existsSync(uuid.v4()) | ||
} |