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
9 changed files
with
111 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
title: quine | ||
description: Enforce quines | ||
--- | ||
|
||
<script setup lang="ts"> | ||
import CodeEditor from '../../.vitepress/theme/components/code-editor.vue'; | ||
import {ruleName, initialText} from '../../src/sample-code/quine'; | ||
</script> | ||
|
||
> "This sentence contains thirty-six characters." | ||
# Enforce quines (`quine`) | ||
|
||
💼 This rule is enabled in the 🌐 `all` [config](/configs/). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
## 💡 Examples | ||
|
||
::: code-group | ||
|
||
<!-- prettier-ignore --> | ||
```js [Center] | ||
// ✅ Correct | ||
($=_=>`($=${$})()`)() | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```js [Right] | ||
// ✅ Correct | ||
( function quine() {console.log("( " + quine.toString() + " )()")} )() | ||
``` | ||
|
||
::: | ||
|
||
## 🔧 Config | ||
|
||
```js | ||
{ rules: { 'ninja/quine': 2 } } | ||
``` |
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
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,39 @@ | ||
import type { RuleContext, RuleListener } from '../utils/eslint-types/Rule' | ||
|
||
import { createEslintRule } from '../utils/create-eslint-rule' | ||
|
||
type MESSAGE_ID = 'not a quine' | ||
|
||
type Options = [] | ||
|
||
export const RULE_NAME = 'quine' | ||
type Context = RuleContext<MESSAGE_ID, Options> | ||
|
||
export default createEslintRule<Options, MESSAGE_ID>({ | ||
name: RULE_NAME, | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'enforce quine', | ||
}, | ||
schema: [{ type: 'object' }], | ||
messages: { | ||
'not a quine': 'not a quine', | ||
}, | ||
}, | ||
defaultOptions: [], | ||
create: (context: Context): RuleListener => { | ||
const sourceCode = context.getSourceCode() | ||
const text = sourceCode?.text || '' | ||
const processCode = (code: string) => { | ||
// eslint-disable-next-line no-eval | ||
const evalResult = eval(code) | ||
if (code !== evalResult) | ||
context.report({ | ||
messageId: 'not a quine', | ||
loc: { column: 0, line: 1 }, | ||
}) | ||
} | ||
return { Program: () => processCode(text) } | ||
}, | ||
}) |
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,8 @@ | ||
import type { PresetConfig } from './presets' | ||
|
||
export const presetConfigs = [] satisfies PresetConfig[] | ||
|
||
export const ruleName = 'quine' | ||
|
||
// eslint-disable-next-line no-template-curly-in-string | ||
export const initialText = '($=_=>`($=${$})()`)()' |