Skip to content

Commit

Permalink
chore: migrate over to eslint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed Apr 10, 2024
1 parent 828a233 commit 62b6c78
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 64 deletions.
51 changes: 0 additions & 51 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Dependencies
node_modules/
package-lock.json
bun.lockb

# Code Coverage
.nyc_output/
coverage/

# Build
dist/

# Mac files
.DS_Store
61 changes: 61 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginEslintPlugin from 'eslint-plugin-eslint-plugin';
import importPlugin from 'eslint-plugin-import';
import comments from '@eslint-community/eslint-plugin-eslint-comments/configs';
import unicornPlugin from 'eslint-plugin-unicorn';
import babelParser from '@babel/eslint-parser';
import globals from 'globals';

/** @type {import('eslint').Linter.FlatConfig[] | import('eslint').Linter.Config} */
export default [
...[
eslint.configs.recommended,
eslintPluginEslintPlugin.configs['flat/recommended'],
importPlugin.configs.typescript,
comments.recommended,
unicornPlugin.configs['flat/recommended']
].map((config) => ({
...config,
ignores: ['dist/**/*', 'coverage/**/*']
})),

{
ignores: ['dist/**/*', 'coverage/**/*'],
languageOptions: {
parser: babelParser,
parserOptions: {
requireConfigFile: false,
ecmaVersion: 2023
},
globals: {
...globals.node
}
},
rules: {
'eslint-plugin/test-case-property-ordering': 'error',
'eslint-plugin/test-case-shorthand-strings': 'error',
'unicorn/prefer-module': 'off',
'unicorn/filename-case': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/prefer-array-find': 'error',
'unicorn/no-null': 'off',
'unicorn/prefer-at': 'off',
'@eslint-community/eslint-comments/no-unused-disable': 'error'
}
},
...tseslint.config(...tseslint.configs.recommended).flatMap((config) => ({
...config,
files: ['**/*.ts']
})),
{
files: ['tests/**/*.ts'],
languageOptions: {
globals: {
...globals.mocha
}
}
}
];
8 changes: 6 additions & 2 deletions lib/rules/metadata-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export default {
'ensure there is a newline between the metadata and the code',
category: 'Best Practices'
},
fixable: 'whitespace'
fixable: 'whitespace',
messages: {
newlineBetween:
'There should be a newline between the metadata and the code'
}
},
create: (context) => {
const sourceCode = context.sourceCode;
Expand Down Expand Up @@ -37,7 +41,7 @@ export default {

if (lineNextToMetadata.trim().length > 0) {
context.report({
message: 'There should be a newline between the metadata and the code',
messageId: 'newlineBetween',
loc: metadataLastLineLoc,
fix: function (fixer) {
const range = [
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
"test": "mocha --recursive --file $(find tests -type f -name \"*.ts\") -r esbuild-runner/register",
"build": "tsup",
"type-check": "tsc --noEmit",
"lint": "eslint . --ignore-path .gitignore && prettier --check . --ignore-path .gitignore && markdownlint . --ignore-path .gitignore",
"lint:fix": "eslint . --ignore-path .gitignore --fix && prettier --write . --ignore-path .gitignore && markdownlint --fix . --ignore-path .gitignore",
"lint": "eslint && prettier --check . --ignore-path .gitignore && markdownlint . --ignore-path .gitignore",
"lint:fix": "eslint --fix && prettier --write . --ignore-path .gitignore && markdownlint --fix . --ignore-path .gitignore",
"prepare": "husky install"
},
"dependencies": {
"semver": "^7.3.8"
},
"devDependencies": {
"@babel/eslint-parser": "^7.23.3",
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@eslint/js": "^9.0.0",
"@types/eslint": "^8.44.8",
"@types/estree": "1.0.5",
"@types/json-schema": "^7.0.15",
Expand All @@ -32,11 +34,11 @@
"@typescript-eslint/parser": "^6.17.0",
"esbuild": "^0.20.0",
"esbuild-runner": "^2.2.2",
"eslint": "8.56.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint": "9.0.0",
"eslint-plugin-eslint-plugin": "^5.0.8",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unicorn": "^50.0.1",
"eslint-plugin-unicorn": "^52.0.0",
"globals": "^15.0.0",
"husky": "^9.0.6",
"json-schema": "^0.4.0",
"live-server": "^1.2.2",
Expand All @@ -47,13 +49,14 @@
"prettier": "^3.1.1",
"should": "^13.2.3",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"typescript-eslint": "^7.6.0"
},
"peerDependencies": {
"eslint": ">=8.40.0 <10"
"eslint": ">=8.40.0 <11"
},
"engines": {
"node": ">=18.0.0 <22.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"license": "MIT",
"homepage": "https://github.com/Yash-Singh1/eslint-plugin-userscripts#readme",
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/metadata-spacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ruleTester.run('metadata-spacing', metadataSpacing, {
// ==/UserScript==
console.log("wow")`,
errors: [{}]
errors: [{ messageId: 'newlineBetween' }]
},

{
Expand All @@ -95,15 +95,15 @@ ruleTester.run('metadata-spacing', metadataSpacing, {
// ==/UserScript==
console.log("stuff")`,
errors: [{}]
errors: [{ messageId: 'newlineBetween' }]
},

{
code: `// ==UserScript==
// ==/UserScript==\r\nconsole.log("stuff")`,
output: `// ==UserScript==
// ==/UserScript==\n\r\nconsole.log("stuff")`,
errors: [{}]
errors: [{ messageId: 'newlineBetween' }]
}
]
});

0 comments on commit 62b6c78

Please sign in to comment.