Skip to content

Commit

Permalink
minor #95 Replace ESLint and Prettier by Biome.js (Kocal)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the main branch.

Discussion
----------

Replace ESLint and Prettier by Biome.js

One single tool to lint and format the code, it's **super** fast

Commits
-------

e6e7cd8 [CI] Improve "coding-style" job, and run Biome instead
deeb168 Replace ESLint and Prettier by Biome.js
  • Loading branch information
Kocal committed Jan 13, 2025
2 parents 9bf462e + e6e7cd8 commit a0c1556
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 145 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Symfony UX
name: Test

on:
pull_request:
Expand All @@ -10,11 +10,18 @@ jobs:
coding-style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Prettier
run: |
yarn
yarn run check-format
- uses: actions/checkout@v4

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 14 # lowest supported version

- name: Install Yarn Dependencies
run: yarn install

- name: Run Biome
run: yarn run ci

tests:
name: Tests (Node.js ${{ matrix.node-versions }})
Expand Down
6 changes: 0 additions & 6 deletions .prettierrc.json

This file was deleted.

5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
};
31 changes: 31 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"include": ["*.js", "src/**/*.[jt]s", "test/**/*.[jt]s"],
"ignore": ["**/package.json", "**/node_modules", "dist/**", "test/dist/**", "test/fixtures/**/dist/**"]
},
"formatter": {
"lineWidth": 120,
"indentStyle": "space",
"indentWidth": 4
},
"linter": {
"rules": {
"complexity": {
"noForEach": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noEmptyBlockStatements": "off",
"noRedundantUseStrict": "off"
}
}
},
"javascript": {
"formatter": {
"trailingCommas": "es5",
"bracketSameLine": true,
"quoteStyle": "single"
}
}
}
12 changes: 5 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const path = require('path');
const path = require('node:path');

module.exports = {
testRegex: "test/.*\\.test.ts",
testRegex: 'test/.*\\.test.ts',
testEnvironment: 'jsdom',
setupFilesAfterEnv: [
path.join(__dirname, 'test/setup.js'),
],
setupFilesAfterEnv: [path.join(__dirname, 'test/setup.js')],
transform: {
'\\.(j|t)s$': ['babel-jest', { configFile: path.join(__dirname, './babel.config.js') }]
'\\.(j|t)s$': ['babel-jest', { configFile: path.join(__dirname, './babel.config.js') }],
},
}
};
48 changes: 3 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
"build": "yarn rollup -c",
"build-types": "yarn tsc",
"test": "yarn run webpack --config test/webpack.config.js && yarn run jest",
"lint": "yarn run eslint src test",
"format": "prettier src/*.ts test/*.js --write",
"check-lint": "yarn lint --no-fix",
"check-format": "yarn format --no-write --check"
"check": "biome check",
"ci": "biome ci"
},
"peerDependencies": {
"@hotwired/stimulus": "^3.0"
Expand All @@ -33,20 +31,15 @@
"@babel/plugin-proposal-class-properties": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@biomejs/biome": "^1.9.4",
"@hotwired/stimulus": "^3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.3.0",
"@symfony/mock-module": "file:test/fixtures/module",
"@symfony/stimulus-testing": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"babel-jest": "^27.3.1",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.0.0",
"eslint-plugin-jest": "^25.2.2",
"jest": "^27.3.1",
"prettier": "^2.2.1",
"rollup": "^2.52.2",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
Expand All @@ -56,41 +49,6 @@
"resolutions": {
"@types/jest": "^27.0"
},
"eslintConfig": {
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": [
"test/dist/**",
"test/fixtures/**",
"test/webpack.config.js"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
},
"env": {
"browser": true
},
"overrides": [
{
"files": [
"test/**/*.ts"
],
"extends": [
"plugin:jest/recommended"
]
}
]
},
"files": [
"src/",
"dist/",
Expand Down
25 changes: 7 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import path from 'path';
import commonjs from '@rollup/plugin-commonjs';

export default [
/*
Expand All @@ -16,12 +16,9 @@ export default [
external: [
// avoids rollup from trying to parse this import
'./webpack/loader!@symfony/stimulus-bridge/controllers.json',
'@hotwired/stimulus'
],
plugins: [
resolve(),
typescript(),
'@hotwired/stimulus',
],
plugins: [resolve(), typescript()],
},

/*
Expand All @@ -36,9 +33,7 @@ export default [
file: path.join('dist', 'webpack', 'loader.js'),
format: 'cjs',
},
external: [
'webpack/lib/dependencies/LoaderDependency',
],
external: ['webpack/lib/dependencies/LoaderDependency'],
plugins: [
resolve(),
typescript(),
Expand All @@ -58,13 +53,7 @@ export default [
file: path.join('dist', 'webpack', 'lazy-controller-loader.js'),
format: 'cjs',
},
external: [
'loader-utils',
'schema-utils',
],
plugins: [
resolve(),
typescript(),
],
external: ['loader-utils', 'schema-utils'],
plugins: [resolve(), typescript()],
},
];
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* file that was distributed with this source code.
*/

'use strict';

import { Application } from '@hotwired/stimulus';
import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers';

Expand All @@ -29,8 +27,7 @@ export function startStimulusApp(context: __WebpackModuleApi.RequireContext) {
}

for (const controllerName in symfonyControllers) {
// eslint-disable-next-line no-prototype-builtins
if (!symfonyControllers.hasOwnProperty(controllerName)) {
if (!Object.prototype.hasOwnProperty.call(symfonyControllers, controllerName)) {
continue;
}

Expand Down
10 changes: 4 additions & 6 deletions src/util/get-stimulus-comment-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
* file that was distributed with this source code.
*/

'use strict';

import { Comment, parse } from 'acorn';
import vm from 'vm';
import vm from 'node:vm';
import { type Comment, parse } from 'acorn';

const stimulusCommentRegExp = new RegExp(/(^|\W)stimulus[A-Z]{1,}[A-Za-z]{1,}:/);

Expand All @@ -19,7 +17,7 @@ const EMPTY_COMMENT_OPTIONS = {
errors: [],
};

function getCommentsFromSource(source: string) {
function getCommentsFromSource(source: string): Comment[] {
const comments: Comment[] = [];
parse(source, {
onComment: comments,
Expand All @@ -34,7 +32,7 @@ function getCommentsFromSource(source: string) {
* Inspired by Webpack's JavaScriptParser
*/
export default function (source: string) {
let comments;
let comments: Comment[] = [];
try {
comments = getCommentsFromSource(source);
} catch (e) {
Expand Down
22 changes: 10 additions & 12 deletions src/webpack/create-controllers-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@
* file that was distributed with this source code.
*/

'use strict';

import generateLazyController from './generate-lazy-controller';

export default function createControllersModule(config: any) {
let controllerContents = 'export default {';
let importStatementContents = '';
let hasLazyControllers = false;

if ('undefined' !== typeof config['placeholder']) {
if ('undefined' !== typeof config.placeholder) {
throw new Error(
'Your controllers.json file was not found. Be sure to add a Webpack alias from "@symfony/stimulus-bridge/controllers.json" to *your* controllers.json file.'
);
}

if ('undefined' === typeof config['controllers']) {
if ('undefined' === typeof config.controllers) {
throw new Error('Your Stimulus configuration file (assets/controllers.json) lacks a "controllers" key.');
}

let controllerIndex = 0;
for (const packageName in config.controllers) {
let packageConfig;
let packageConfig: unknown;
try {
packageConfig = require(packageName + '/package.json');
packageConfig = require(`${packageName}/package.json`);
} catch (e) {
throw new Error(
`The file "${packageName}/package.json" could not be found. Try running "yarn install --force".`
);
}

for (const controllerName in config.controllers[packageName]) {
const controllerReference = packageName + '/' + controllerName;
const controllerReference = `${packageName}/${controllerName}`;

// Find package config for the controller
if ('undefined' === typeof packageConfig.symfony.controllers[controllerName]) {
throw new Error(
'Controller "' + controllerReference + '" does not exist in the package and cannot be compiled.'
`Controller "${controllerReference}" does not exist in the package and cannot be compiled.`
);
}

Expand All @@ -54,10 +52,10 @@ export default function createControllersModule(config: any) {
continue;
}

const controllerMain = packageName + '/' + controllerPackageConfig.main;
let fetchMode = controllerUserConfig.fetch || 'eager';
const controllerMain = `${packageName}/${controllerPackageConfig.main}`;
const fetchMode = controllerUserConfig.fetch || 'eager';

let moduleValueContents = ``;
let moduleValueContents = '';
if (fetchMode === 'eager') {
const controllerNameForVariable = `controller_${controllerIndex++}`;
importStatementContents += `import ${controllerNameForVariable} from '${controllerMain}';\n`;
Expand Down Expand Up @@ -85,7 +83,7 @@ export default function createControllersModule(config: any) {

for (const autoimport in controllerUserConfig.autoimport || []) {
if (controllerUserConfig.autoimport[autoimport]) {
importStatementContents += "import '" + autoimport + "';\n";
importStatementContents += `import '${autoimport}';\n`;
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/webpack/generate-lazy-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
* file that was distributed with this source code.
*/

'use strict';

/**
*
* @param {string} controllerPath The importable path to the controller
* @param {Number} indentationSpaces Amount each line should be indented
* @param {string} exportName The name of the module that's exported from the controller
*/
export default function(controllerPath: string, indentationSpaces: number, exportName = 'default') {
export default function (controllerPath: string, indentationSpaces: number, exportName = 'default') {
const spaces = ' '.repeat(indentationSpaces);

return `class extends Controller {
Expand Down
6 changes: 2 additions & 4 deletions src/webpack/lazy-controller-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
* file that was distributed with this source code.
*/

'use strict';

import generateLazyController from './generate-lazy-controller';
import getStimulusCommentOptions from '../util/get-stimulus-comment-options';
import * as loaderUtils from 'loader-utils';
import * as schemaUtils from 'schema-utils';
import getStimulusCommentOptions from '../util/get-stimulus-comment-options';
import generateLazyController from './generate-lazy-controller';

const schema = {
type: 'object',
Expand Down
2 changes: 0 additions & 2 deletions src/webpack/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* file that was distributed with this source code.
*/

'use strict';

import LoaderDependency from 'webpack/lib/dependencies/LoaderDependency';
import createControllersModule from './create-controllers-module';

Expand Down
2 changes: 0 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* file that was distributed with this source code.
*/

'use strict';

import { startStimulusApp } from './dist/index';

describe('startStimulusApp', () => {
Expand Down
Loading

0 comments on commit a0c1556

Please sign in to comment.