https://github.com/daeh/eslint-template

ESLint Flat Config with Stylish Plugin

https://github.com/daeh/eslint-template

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.2%) to scientific vocabulary

Keywords

eslint eslint-config firebase prettier template typescript webppl
Last synced: 5 months ago · JSON representation

Repository

ESLint Flat Config with Stylish Plugin

Basic Info
  • Host: GitHub
  • Owner: daeh
  • License: mit
  • Language: JavaScript
  • Default Branch: main
  • Homepage:
  • Size: 498 KB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Topics
eslint eslint-config firebase prettier template typescript webppl
Created over 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

ESLint Template

This is a future-looking configuration that implements the major developments from ESLint.

ESLint Flat Config System

Beginning in ESLint v9.0.0, the default will be the new flat config system. This will deprecating the Common.js Module config system (which uses .eslintrc.js), replacing it with the ES Module config system (which uses eslint.config.js).

ESLint Stylistic

ESLint is deprecating formatting rules, passing over maintenance and development to the community-run plugin ESLint Stylistic.

This Example Config

The main file in this repo is the flat ESLint config, eslint.config.mjs.

This project is configured as an ES Module, so this config file could be named eslint.config.js, but I have given it the .mjs extension to make this config work for Common.js Module development with minimal reconfiguration.

While ESLint has no issue using the .mjs config file, at present, IDEs like VS Code and IntelliJ IDEA require the .js extension. A simple workaround is to make an alias eslint.config.js that points to eslint.config.mjs. This is done automatically during install by the package.json file.

This project uses TypeScript and Prettier, which are configured in tsconfig.json and prettier.config.mjs. The ESLint config integrates these configurations.

WebPPL

I have included an example of how to use ESLint to format WebPPL code. All of the WebPPL-specific configuration can be removed if not desired without affecting the linting and formatting of JavaScript and TypeScript.

Installation

  • Fork this repo: Use this template > Create a new repository
  • Git clone the forked repo
  • Enter the repo folder

  • Install the dependencies using Yarn, e.g.

```shell

Clone your forked repo to the current working directory

Replace daeh/eslint-template with your username and repo name

git clone --branch main https://github.com/daeh/eslint-template.git eslint-template

Enter the new directory

cd eslint-template || exit

Install Node packages

yarn install ```

VS Code Settings

For VS Code to respect the configuration, you need to specify the formatter for the relevant files. This is done for you in VSCodeProject.code-workspace and in .vscode/settings.json (these are redundant, you only need one). This configures the ESLint extension to use the flat config system, makes VS Code use the Prettier - Code Formatter extensions for formatting Javascript, HTML, JSON, and CSS files, and lets ESLint format WebPPL files. This obviously requires the ESLint and Prettier extensions to be enabled for the workspace. Activate the VSCodeProject.code-workspace via File > Open Workspace from File... (or by double clicking it), activate .vscode via File > Open Folder... in VS Code.

The relevant settings are:

json { "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" }, "files.associations": { "*.wppl": "javascript" }, "[javascript][javascriptreact][typescript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, "[wppl]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, "[html]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[json][jsonc]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[css][scss][less]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "eslint.useFlatConfig": true, "typescript.enablePromptUseWorkspaceTsdk": true, }

IntelliJ IDEA Settings

For IntelliJ IDEA / WebStorm to respect the configuration, you need to enable ESLint and Prettier for the relevant filetypes. There is an example config in .idea. To enable ESLing and Prettier manually:

  • Settings... > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint
    • Enable Automatic ESLint configuration
    • Enable Run eslint --fix on save
    • Add the additional filetypes to the Run for files field:
    • {**/*,*}.{ts,mts,cts,tsx,mtsx,js,mjs,cjs,jsx,mjsx,html,wppl}
  • Settings... > Languages & Frameworks > JavaScript > Prettier
    • Enable Automatic Prettier configuration
    • Enable Run on save
    • Add the additional filetypes to the Run for files field:
    • {**/*,*}.{ts,mts,cts,tsx,mtsx,js,mjs,cjs,jsx,mjsx,json,html,css,scss,vue,astro}

If you change the project from an ES Module to a Common.js Module, or if ESLint isn't working, try this fix from Ditlef Diseth:

  • Settings... > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint
    • Switch to Manual ESLint configuration
    • Add this string to the Extra ESLint options field: shell ESLINT_USE_FLAT_CONFIG=true yarn eslint --config eslint.config.mjs

Usage

Once your IDE settings are configured, you should see unused variable warnings in the three test files provided in src/.

You can format, lint and build the project from the command line by calling the commands in package.json,

json { "scripts": { "lint": "export ESLINT_USE_FLAT_CONFIG=true && prettier --config prettier.config.mjs --write . && eslint --config eslint.config.mjs --fix . && tsc --project tsconfig.json --noEmit" } }

by running yarn lint, etc.

Author

Personal Website BlueSky Twitter

Owner

  • Name: Dae
  • Login: daeh
  • Kind: user
  • Location: Cambridge, MA
  • Company: MIT

Neukom Computational Science Postdoc Fellow at Dartmouth. PhD from MIT Brain and Cognitive Sciences.

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

package-lock.json npm
  • 258 dependencies
package.json npm
  • @eslint/js ^8.53.0 development
  • @stylistic/eslint-plugin-js ^1.2.0 development
  • @stylistic/eslint-plugin-ts ^1.2.0 development
  • @typescript-eslint/eslint-plugin ^6.10.0 development
  • @typescript-eslint/parser ^6.10.0 development
  • eslint ^8.53.0 development
  • eslint-config-prettier ^9.0.0 development
  • eslint-plugin-import ^2.29.0 development
  • eslint-plugin-prettier ^5.0.1 development
  • globals ^13.23.0 development
  • path ^0.12.7 development
  • url ^0.11.3 development