From aad24fb24ffcf3c8676756bcd87c8b5a610caaef Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 10:20:31 +0100 Subject: [PATCH 1/7] Migrate to ESM --- .eslintrc | 3 +-- .mocharc.json | 4 ++-- package.json | 31 ++++++++++++++++--------------- rollup.config.js | 2 +- src/rules/no-disable/rule.ts | 6 ++++-- src/rules/no-obsolete/rule.ts | 4 +++- src/rules/unit-step/rule.ts | 4 +++- tests/no-disable.spec.ts | 2 +- tests/no-obsolete.spec.ts | 3 ++- tests/unit-step.spec.ts | 2 +- tsconfig.json | 2 +- 11 files changed, 35 insertions(+), 28 deletions(-) diff --git a/.eslintrc b/.eslintrc index c6fb3d4..a0a1aef 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,6 @@ ], "rules": { - "@typescript-eslint/ban-ts-comment": "warn", - "unicorn/prefer-at": "warn" + "@typescript-eslint/ban-ts-comment": "warn" } } diff --git a/.mocharc.json b/.mocharc.json index e8d9cab..681c82a 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -5,8 +5,8 @@ ], "node-option": [ - "experimental-specifier-resolution=node", - "loader=ts-node/esm" + "experimental-specifier-resolution node", + "loader ts-node/esm" ], "spec": "tests/**/*.spec.ts" } diff --git a/package.json b/package.json index b035617..775be33 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "@isnotdefined/stylelint-plugin", "description": "Yet another Stylelint plugin", - "version": "3.1.0", + "version": "4.0.0-beta.1", "license": "MIT", + "type": "module", "keywords": [ "stylelint", @@ -32,30 +33,30 @@ }, "peerDependencies": { - "stylelint": "^15" + "stylelint": "^16" }, "devDependencies": { - "@isnotdefined/eslint-config": "8.1.0", + "@isnotdefined/eslint-config": "9.8.0", "@types/chai": "4.3.11", "@types/mocha": "10.0.6", - "@types/node": "20.10.0", - "@types/postcss-plugins": "1.13.0", - "chai": "4.3.7", - "eslint": "8.34.0", + "@types/node": "20.10.4", + "@types/postcss-plugins": "1.13.2", + "chai": "4.3.10", + "eslint": "8.55.0", "mocha": "10.2.0", - "rollup": "2.79.1", - "rollup-plugin-copy": "3.4.0", + "rollup": "4.8.0", + "rollup-plugin-copy": "3.5.0", "rollup-plugin-delete": "2.0.0", - "rollup-plugin-ts": "3.1.1", - "stylelint": "15.11.0", - "ts-node": "10.9.1", - "typescript": "4.9.5" + "rollup-plugin-ts": "3.4.5", + "stylelint": "16.0.2", + "ts-node": "10.9.2", + "typescript": "5.3.3" }, "scripts": { - "build": "rollup --config=rollup.config.js", - "lint": "eslint src tests --ext=.ts", + "build": "rollup --config rollup.config.js", + "lint": "eslint src tests --ext .ts", "fix": "npm run lint -- --fix", "test": "mocha" }, diff --git a/rollup.config.js b/rollup.config.js index 99dabad..95feb3f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,7 @@ import del from 'rollup-plugin-delete'; import ts from 'rollup-plugin-ts'; import copy from 'rollup-plugin-copy'; -import PACKAGE from './package.json'; +import PACKAGE from './package.json' assert { type: 'json' }; export default { diff --git a/src/rules/no-disable/rule.ts b/src/rules/no-disable/rule.ts index 888278b..ccae578 100644 --- a/src/rules/no-disable/rule.ts +++ b/src/rules/no-disable/rule.ts @@ -1,8 +1,10 @@ import { Root } from 'postcss'; import stylelint, { Rule, PostcssResult } from 'stylelint'; + +import { wording } from '../wording'; + import { defaultOptions } from './option'; import { Options } from './option.interface'; -import { wording } from '../wording'; const { utils, createPlugin } : typeof stylelint = stylelint; const ruleName : string = '@isnotdefined/no-disable'; @@ -30,7 +32,7 @@ function rule(primaryOptions : Options) { root.walkComments(comment => { - if (options.commands.includes(comment.text.split(' ')[0])) + if (options.commands.includes(comment.text.split(' ').at(0))) { utils.report( { diff --git a/src/rules/no-obsolete/rule.ts b/src/rules/no-obsolete/rule.ts index a9777db..6a4bb6c 100644 --- a/src/rules/no-obsolete/rule.ts +++ b/src/rules/no-obsolete/rule.ts @@ -1,8 +1,10 @@ import { Root } from 'postcss'; import stylelint, { Rule, RuleContext, PostcssResult } from 'stylelint'; + +import { wording } from '../wording'; + import { defaultOptions } from './option'; import { Options, AtRule, Property } from './option.interface'; -import { wording } from '../wording'; const { utils, createPlugin } : typeof stylelint = stylelint; const ruleName : string = '@isnotdefined/no-obsolete'; diff --git a/src/rules/unit-step/rule.ts b/src/rules/unit-step/rule.ts index 2ec28f4..1b58df8 100644 --- a/src/rules/unit-step/rule.ts +++ b/src/rules/unit-step/rule.ts @@ -1,9 +1,11 @@ import { Root } from 'postcss'; import { ContainerBase, parse } from 'postcss-values-parser'; import stylelint, { Rule, RuleContext, PostcssResult } from 'stylelint'; + +import { wording } from '../wording'; + import { defaultOptions } from './option'; import { Options } from './option.interface'; -import { wording } from '../wording'; const { utils, createPlugin } : typeof stylelint = stylelint; const ruleName : string = '@isnotdefined/unit-step'; diff --git a/tests/no-disable.spec.ts b/tests/no-disable.spec.ts index 8ce6af1..70a18d0 100644 --- a/tests/no-disable.spec.ts +++ b/tests/no-disable.spec.ts @@ -31,7 +31,7 @@ describe('no-disable', () => } }); - expect(linterResult.results[0]._postcssResult.messages[index].text).to.equal(message); + expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); }); }); diff --git a/tests/no-obsolete.spec.ts b/tests/no-obsolete.spec.ts index 8e297eb..760bd4e 100644 --- a/tests/no-obsolete.spec.ts +++ b/tests/no-obsolete.spec.ts @@ -1,5 +1,6 @@ import { expect } from 'chai'; import stylelint, { LinterResult } from 'stylelint'; + const { lint } : typeof stylelint = stylelint; describe('no-obsolete', () => @@ -59,7 +60,7 @@ describe('no-obsolete', () => } }); - expect(linterResult.results[0]._postcssResult.messages[index].text).to.equal(message); + expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); }); }); diff --git a/tests/unit-step.spec.ts b/tests/unit-step.spec.ts index 6f1134e..efd84c3 100644 --- a/tests/unit-step.spec.ts +++ b/tests/unit-step.spec.ts @@ -31,7 +31,7 @@ describe('unit-step', () => } }); - expect(linterResult.results[0]._postcssResult.messages[index].text).to.equal(message); + expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); }); }); diff --git a/tsconfig.json b/tsconfig.json index 361070b..3651793 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ { "outDir": "build", "target": "es2015", - "module": "commonjs", + "module": "esnext", "moduleResolution": "node", "declaration": true, "esModuleInterop": true From 0f34fad3798adf37a9be29d0897bcd5ae52bff01 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 10:24:35 +0100 Subject: [PATCH 2/7] Fix options --- .mocharc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mocharc.json b/.mocharc.json index 681c82a..e8d9cab 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -5,8 +5,8 @@ ], "node-option": [ - "experimental-specifier-resolution node", - "loader ts-node/esm" + "experimental-specifier-resolution=node", + "loader=ts-node/esm" ], "spec": "tests/**/*.spec.ts" } From 7aa07e7a7e5c0fded269743bd89f80636d3e1d86 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 10:33:23 +0100 Subject: [PATCH 3/7] Update to Node 20 --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5dce9e..59b2838 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Node 18 + - name: Set up Node 20 uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - run: npm install - run: npm run lint build: @@ -19,10 +19,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Node 18 + - name: Set up Node 20 uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - run: npm install - run: npm run build test: @@ -30,9 +30,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Set up Node 18 + - name: Set up Node 20 uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - run: npm install - run: npm run test From a966401f625799763ebef7bbd7717927c2dc2d14 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 10:42:24 +0100 Subject: [PATCH 4/7] Add configBasedir --- tests/no-disable.spec.ts | 5 +++-- tests/no-obsolete.spec.ts | 6 ++++-- tests/unit-step.spec.ts | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/no-disable.spec.ts b/tests/no-disable.spec.ts index 70a18d0..672c234 100644 --- a/tests/no-disable.spec.ts +++ b/tests/no-disable.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import stylelint, { LinterResult } from 'stylelint'; +import stylelint, { LinterResult, LinterOptions } from 'stylelint'; const { lint } : typeof stylelint = stylelint; @@ -16,6 +16,7 @@ describe('no-disable', () => { const linterResult : LinterResult = await lint( { + configBasedir: '.', files: './tests/providers/no-disable.css', config: { @@ -29,7 +30,7 @@ describe('no-disable', () => }, ignoreDisables: true } - }); + } as LinterOptions); expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); diff --git a/tests/no-obsolete.spec.ts b/tests/no-obsolete.spec.ts index 760bd4e..98a4931 100644 --- a/tests/no-obsolete.spec.ts +++ b/tests/no-obsolete.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import stylelint, { LinterResult } from 'stylelint'; +import stylelint, { LinterResult, LinterOptions } from 'stylelint'; const { lint } : typeof stylelint = stylelint; @@ -46,9 +46,11 @@ describe('no-obsolete', () => { const linterResult : LinterResult = await lint( { + configBasedir: '.', files: './tests/providers/no-obsolete.css', config: { + configBasedir: '.', plugins: [ './src' @@ -58,7 +60,7 @@ describe('no-obsolete', () => '@isnotdefined/no-obsolete': true } } - }); + } as LinterOptions); expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); diff --git a/tests/unit-step.spec.ts b/tests/unit-step.spec.ts index efd84c3..caa3dd3 100644 --- a/tests/unit-step.spec.ts +++ b/tests/unit-step.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import stylelint, { LinterResult } from 'stylelint'; +import stylelint, { LinterResult, LinterOptions } from 'stylelint'; const { lint } : typeof stylelint = stylelint; @@ -17,6 +17,7 @@ describe('unit-step', () => { const linterResult : LinterResult = await lint( { + configBasedir: '.', files: './tests/providers/unit-step.css', config: { @@ -29,7 +30,7 @@ describe('unit-step', () => '@isnotdefined/unit-step': true } } - }); + } as LinterOptions); expect(linterResult.results.at(0)._postcssResult.messages[index].text).to.equal(message); }); From 508aeee19265842c4e7850c416a4c2575b4a4069 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 10:49:28 +0100 Subject: [PATCH 5/7] Resolve path --- tests/no-disable.spec.ts | 5 +++-- tests/no-obsolete.spec.ts | 6 +++--- tests/unit-step.spec.ts | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/no-disable.spec.ts b/tests/no-disable.spec.ts index 672c234..ebbb259 100644 --- a/tests/no-disable.spec.ts +++ b/tests/no-disable.spec.ts @@ -1,3 +1,5 @@ +import path from 'path'; + import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -16,13 +18,12 @@ describe('no-disable', () => { const linterResult : LinterResult = await lint( { - configBasedir: '.', files: './tests/providers/no-disable.css', config: { plugins: [ - './src' + path.resolve('./src') ], rules: { diff --git a/tests/no-obsolete.spec.ts b/tests/no-obsolete.spec.ts index 98a4931..fb51046 100644 --- a/tests/no-obsolete.spec.ts +++ b/tests/no-obsolete.spec.ts @@ -1,3 +1,5 @@ +import path from 'path'; + import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -46,14 +48,12 @@ describe('no-obsolete', () => { const linterResult : LinterResult = await lint( { - configBasedir: '.', files: './tests/providers/no-obsolete.css', config: { - configBasedir: '.', plugins: [ - './src' + path.resolve('./src') ], rules: { diff --git a/tests/unit-step.spec.ts b/tests/unit-step.spec.ts index caa3dd3..ad0b9bb 100644 --- a/tests/unit-step.spec.ts +++ b/tests/unit-step.spec.ts @@ -1,3 +1,5 @@ +import path from 'path'; + import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -17,13 +19,12 @@ describe('unit-step', () => { const linterResult : LinterResult = await lint( { - configBasedir: '.', files: './tests/providers/unit-step.css', config: { plugins: [ - './src' + path.resolve('./src') ], rules: { From 65ba15cb636bb4038561866bb53d2149a0a1d84f Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 11:17:18 +0100 Subject: [PATCH 6/7] Resolve path --- package.json | 4 +--- tests/no-disable.spec.ts | 2 +- tests/no-obsolete.spec.ts | 2 +- tests/unit-step.spec.ts | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 775be33..04bbba4 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,5 @@ "lint": "eslint src tests --ext .ts", "fix": "npm run lint -- --fix", "test": "mocha" - }, - "main": "index.cjs", - "module": "index.mjs" + } } diff --git a/tests/no-disable.spec.ts b/tests/no-disable.spec.ts index ebbb259..0370c23 100644 --- a/tests/no-disable.spec.ts +++ b/tests/no-disable.spec.ts @@ -23,7 +23,7 @@ describe('no-disable', () => { plugins: [ - path.resolve('./src') + path.resolve(path.resolve(), './src') ], rules: { diff --git a/tests/no-obsolete.spec.ts b/tests/no-obsolete.spec.ts index fb51046..a0f33c6 100644 --- a/tests/no-obsolete.spec.ts +++ b/tests/no-obsolete.spec.ts @@ -53,7 +53,7 @@ describe('no-obsolete', () => { plugins: [ - path.resolve('./src') + path.resolve(path.resolve(), './src') ], rules: { diff --git a/tests/unit-step.spec.ts b/tests/unit-step.spec.ts index ad0b9bb..e36b1cd 100644 --- a/tests/unit-step.spec.ts +++ b/tests/unit-step.spec.ts @@ -24,7 +24,7 @@ describe('unit-step', () => { plugins: [ - path.resolve('./src') + path.resolve(path.resolve(), './src') ], rules: { From ca42b143fac1f99db23cb5ca49023cc5daf2b2b7 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 13 Dec 2023 12:13:49 +0100 Subject: [PATCH 7/7] Resolve path --- tests/no-disable.spec.ts | 3 +-- tests/no-obsolete.spec.ts | 4 +--- tests/unit-step.spec.ts | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/no-disable.spec.ts b/tests/no-disable.spec.ts index 0370c23..3502f00 100644 --- a/tests/no-disable.spec.ts +++ b/tests/no-disable.spec.ts @@ -1,4 +1,3 @@ -import path from 'path'; import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -23,7 +22,7 @@ describe('no-disable', () => { plugins: [ - path.resolve(path.resolve(), './src') + './src/index.ts' ], rules: { diff --git a/tests/no-obsolete.spec.ts b/tests/no-obsolete.spec.ts index a0f33c6..70de120 100644 --- a/tests/no-obsolete.spec.ts +++ b/tests/no-obsolete.spec.ts @@ -1,5 +1,3 @@ -import path from 'path'; - import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -53,7 +51,7 @@ describe('no-obsolete', () => { plugins: [ - path.resolve(path.resolve(), './src') + './src/index.ts' ], rules: { diff --git a/tests/unit-step.spec.ts b/tests/unit-step.spec.ts index e36b1cd..e13a9b8 100644 --- a/tests/unit-step.spec.ts +++ b/tests/unit-step.spec.ts @@ -1,5 +1,3 @@ -import path from 'path'; - import { expect } from 'chai'; import stylelint, { LinterResult, LinterOptions } from 'stylelint'; @@ -24,7 +22,7 @@ describe('unit-step', () => { plugins: [ - path.resolve(path.resolve(), './src') + './src/index.ts' ], rules: {