Skip to content

Commit 30c870d

Browse files
committed
feat: granular stylistic control
1 parent 91dee42 commit 30c870d

File tree

14 files changed

+319
-67
lines changed

14 files changed

+319
-67
lines changed

fixtures/input/javascript.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ var log = console.log
77
class Person {
88
constructor(name, age) {
99
this.name = name;
10-
this.age = age;
10+
this.age = age;
1111
}
1212

13-
// Define a method within the class
14-
sayHello() {
15-
log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
16-
}
13+
// Define a method within the class
14+
sayHello() {
15+
log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
16+
}
1717
}
1818

1919
// Create an array of objects

fixtures/input/vue.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
<script setup>
1111
// Define reactive data and props
12-
import { ref } from 'vue';
12+
import { ref } from '@vue/reactivity';
1313
1414
const greeting = ref('Hello, Vue 3!' + 1);
15-
let counter = ref(0);
15+
let counter = ref(0)
1616
1717
// Define a function
1818
const incrementCounter = () => {
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This file is generated by ChatGPT
2+
3+
// eslint-disable-next-line no-console
4+
const log = console.log
5+
6+
// Define a class using ES6 class syntax
7+
class Person {
8+
constructor(name, age) {
9+
this.name = name;
10+
this.age = age;
11+
}
12+
13+
// Define a method within the class
14+
sayHello() {
15+
log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
16+
}
17+
}
18+
19+
// Create an array of objects
20+
const people = [
21+
new Person('Alice', 30),
22+
new Person('Bob', 25),
23+
new Person('Charlie', 35)
24+
];
25+
26+
// Use the forEach method to iterate over the array
27+
people.forEach((person) => {
28+
person.sayHello();
29+
});
30+
31+
// Use a template literal to create a multiline string
32+
const multilineString = `
33+
This is a multiline string
34+
that spans multiple lines.
35+
`;
36+
37+
// Use destructuring assignment to extract values from an object
38+
const { name, age } = people[0];
39+
log(`First person in the array is ${name} and they are ${age} years old.`, multilineString);
40+
41+
// Use the spread operator to create a new array
42+
const numbers = [1, 2, 3];
43+
const newNumbers = [...numbers, 4, 5];
44+
log(newNumbers);
45+
46+
// Use a try-catch block for error handling
47+
try {
48+
// Attempt to parse an invalid JSON string
49+
JSON.parse('invalid JSON');
50+
} catch (error) {
51+
console.error('Error parsing JSON:', error.message);
52+
}
53+
54+
// Use a ternary conditional operator
55+
const isEven = num => num % 2 === 0;
56+
const number = 7;
57+
log(`${number} is ${isEven(number) ? 'even' : 'odd'}.`);
58+
59+
// Use a callback function with setTimeout for asynchronous code
60+
setTimeout(() => {
61+
log('This code runs after a delay of 2 seconds.');
62+
}, 2000);
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Define a TypeScript interface
2+
interface Person {
3+
name: string; age: number;
4+
}
5+
6+
// Create an array of objects with the defined interface
7+
const people: Person[] = [
8+
{ name: 'Alice', age: 30 },
9+
{ name: 'Bob', age: 25 },
10+
{ name: 'Charlie',
11+
age: 35 }
12+
];
13+
14+
// eslint-disable-next-line no-console
15+
const log = console.log
16+
17+
// Use a for...of loop to iterate over the array
18+
for (const person of people) {
19+
log(`Hello, my name is ${person.name} and I am ${person.age} years old.`);
20+
}
21+
22+
// Define a generic function
23+
function identity< T >(arg: T): T {
24+
return arg;
25+
}
26+
27+
// Use the generic function with type inference
28+
const result = identity(
29+
'TypeScript is awesome');
30+
log(result);
31+
32+
// Use optional properties in an interface
33+
interface Car {
34+
make: string;
35+
model?: string;
36+
}
37+
38+
// Create objects using the interface
39+
const car1: Car = { make: 'Toyota' };
40+
const car2: Car = {
41+
make: 'Ford', model: 'Focus' };
42+
43+
// Use union types
44+
type Fruit = 'apple' | 'banana' | 'orange';
45+
const favoriteFruit: Fruit = 'apple';
46+
47+
// Use a type assertion to tell TypeScript about the type
48+
const inputValue: any = '42';
49+
const numericValue = inputValue as number;
50+
51+
// Define a class with access modifiers
52+
class Animal {
53+
private name: string;
54+
constructor(name: string) {
55+
this.name = name;
56+
}
57+
protected makeSound(sound: string) {
58+
log(`${this.name} says ${sound}`);
59+
}
60+
}
61+
62+
// Extend a class
63+
class Dog extends Animal {
64+
constructor(private alias: string) {
65+
super(alias);
66+
}
67+
bark() {
68+
this.makeSound('Woof!');
69+
}
70+
}
71+
72+
const dog = new Dog('Buddy');
73+
dog.bark();
74+
75+
function fn (): string {
76+
return `hello${ 1}`
77+
}
78+
79+
log(car1, car2, favoriteFruit, numericValue, fn())

fixtures/output/no-style/vue-ts.vue

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script setup lang="ts">
2+
// Define reactive data and props
3+
import { ref } from 'vue';
4+
5+
const greeting = ref('Hello, Vue 3!');
6+
const counter = ref<number | string>(0);
7+
8+
// Define a function
9+
function incrementCounter () {
10+
counter.value++;
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<h1>{{ greeting }}</h1>
17+
<button @click="incrementCounter">
18+
Click me!
19+
</button>
20+
<p>Counter: {{ counter }}</p>
21+
</div>
22+
</template>

fixtures/output/no-style/vue.vue

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script setup>
2+
// Define reactive data and props
3+
import { ref } from 'vue';
4+
5+
const greeting = ref(`Hello, Vue 3!${ 1}`);
6+
const counter = ref(0)
7+
8+
// Define a function
9+
function incrementCounter () {
10+
counter.value++;
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<h1>
17+
{{ greeting }}
18+
</h1>
19+
<button @click="incrementCounter">
20+
Click me!
21+
</button>
22+
<p>Counter: {{ counter }}</p>
23+
</div>
24+
</template>

src/configs/imports.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import type { FlatESLintConfigItem } from 'eslint-define-config'
22
import { pluginImport } from '../plugins'
3+
import type { OptionsStylistic } from '../types'
4+
5+
export function imports(options: OptionsStylistic = {}): FlatESLintConfigItem[] {
6+
const {
7+
stylistic = true,
8+
} = options
39

4-
export function imports(): FlatESLintConfigItem[] {
510
return [
611
{
712
plugins: {
@@ -10,13 +15,18 @@ export function imports(): FlatESLintConfigItem[] {
1015
rules: {
1116
'import/export': 'error',
1217
'import/first': 'error',
13-
'import/newline-after-import': ['error', { considerComments: true, count: 1 }],
1418
'import/no-duplicates': 'error',
1519
'import/no-mutable-exports': 'error',
1620
'import/no-named-default': 'error',
1721
'import/no-self-import': 'error',
1822
'import/no-webpack-loader-syntax': 'error',
1923
'import/order': 'error',
24+
25+
...stylistic
26+
? {
27+
'import/newline-after-import': ['error', { considerComments: true, count: 1 }],
28+
}
29+
: {},
2030
},
2131
},
2232
]

src/configs/jsdoc.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import type { FlatESLintConfigItem } from 'eslint-define-config'
22
import { pluginJsdoc } from '../plugins'
3+
import type { OptionsStylistic } from '../types'
4+
5+
export function jsdoc(options: OptionsStylistic = {}): FlatESLintConfigItem[] {
6+
const {
7+
stylistic = true,
8+
} = options
39

4-
export function jsdoc(): FlatESLintConfigItem[] {
510
return [
611
{
712
plugins: {
813
jsdoc: pluginJsdoc,
914
},
1015
rules: {
1116
'jsdoc/check-access': 'warn',
12-
'jsdoc/check-alignment': 'warn',
1317
'jsdoc/check-param-names': 'warn',
1418
'jsdoc/check-property-names': 'warn',
1519
'jsdoc/check-types': 'warn',
1620
'jsdoc/empty-tags': 'warn',
1721
'jsdoc/implements-on-classes': 'warn',
18-
'jsdoc/multiline-blocks': 'warn',
1922
'jsdoc/no-defaults': 'warn',
2023
'jsdoc/no-multi-asterisks': 'warn',
2124
'jsdoc/require-param-name': 'warn',
@@ -26,6 +29,13 @@ export function jsdoc(): FlatESLintConfigItem[] {
2629
'jsdoc/require-returns-description': 'warn',
2730
'jsdoc/require-yields-check': 'warn',
2831
'jsdoc/valid-types': 'warn',
32+
33+
...stylistic
34+
? {
35+
'jsdoc/check-alignment': 'warn',
36+
'jsdoc/multiline-blocks': 'warn',
37+
}
38+
: {},
2939
},
3040
},
3141
]

src/configs/jsonc.ts

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import type { FlatESLintConfigItem } from 'eslint-define-config'
22
import { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from '../globs'
33
import { parserJsonc, pluginJsonc } from '../plugins'
4+
import type { OptionsOverrides, OptionsStylistic } from '../types'
5+
6+
export function jsonc(options: OptionsStylistic & OptionsOverrides = {}): FlatESLintConfigItem[] {
7+
const {
8+
stylistic = true,
9+
overrides = {},
10+
} = options
411

5-
export function jsonc(): FlatESLintConfigItem[] {
612
return [
713
{
814
plugins: {
@@ -15,11 +21,7 @@ export function jsonc(): FlatESLintConfigItem[] {
1521
parser: parserJsonc,
1622
},
1723
rules: {
18-
'jsonc/array-bracket-spacing': ['error', 'never'],
19-
'jsonc/comma-dangle': ['error', 'never'],
20-
'jsonc/comma-style': ['error', 'last'],
21-
'jsonc/indent': ['error', 2],
22-
'jsonc/key-spacing': ['error', { afterColon: true, beforeColon: false }],
24+
2325
'jsonc/no-bigint-literals': 'error',
2426
'jsonc/no-binary-expression': 'error',
2527
'jsonc/no-binary-numeric-literals': 'error',
@@ -43,14 +45,26 @@ export function jsonc(): FlatESLintConfigItem[] {
4345
'jsonc/no-undefined-value': 'error',
4446
'jsonc/no-unicode-codepoint-escapes': 'error',
4547
'jsonc/no-useless-escape': 'error',
46-
'jsonc/object-curly-newline': ['error', { consistent: true, multiline: true }],
47-
'jsonc/object-curly-spacing': ['error', 'always'],
48-
'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
49-
'jsonc/quote-props': 'error',
50-
'jsonc/quotes': 'error',
5148
'jsonc/space-unary-ops': 'error',
5249
'jsonc/valid-json-number': 'error',
5350
'jsonc/vue-custom-block/no-parsing-error': 'error',
51+
52+
...stylistic
53+
? {
54+
'jsonc/array-bracket-spacing': ['error', 'never'],
55+
'jsonc/comma-dangle': ['error', 'never'],
56+
'jsonc/comma-style': ['error', 'last'],
57+
'jsonc/indent': ['error', 2],
58+
'jsonc/key-spacing': ['error', { afterColon: true, beforeColon: false }],
59+
'jsonc/object-curly-newline': ['error', { consistent: true, multiline: true }],
60+
'jsonc/object-curly-spacing': ['error', 'always'],
61+
'jsonc/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
62+
'jsonc/quote-props': 'error',
63+
'jsonc/quotes': 'error',
64+
}
65+
: {},
66+
67+
...overrides,
5468
},
5569
},
5670
]

0 commit comments

Comments
 (0)