Skip to content

Commit

Permalink
chore!: convert eslint plugin to esm (#2930)
Browse files Browse the repository at this point in the history
  • Loading branch information
barak007 authored Dec 13, 2023
1 parent ff5faa1 commit 2c441dd
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 227 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-misused-promises": "off" // ToDo: remove once eslint fix issue.
"@typescript-eslint/no-misused-promises": "off", // ToDo: remove once eslint fix issue.
"@typescript-eslint/no-base-to-string": "off" // this rule is not working properly
}
},
{
Expand Down
390 changes: 194 additions & 196 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
"@types/react-dom": "^18.2.17",
"@types/validate-npm-package-name": "^4.0.2",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@typescript-eslint/rule-tester": "^6.13.1",
"autoprefixer": "^10.4.16",
"c8": "^8.0.1",
"chai": "^4.3.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import postcssNested from 'postcss-nested';
import postcssJS from 'postcss-js';
import safeParser from 'postcss-safe-parser';

export type CSSObject = any & object;
export type CSSObject = object;

const processor = postcss([postcssNested()]);

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-kit/src/browser-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function filterAssetResponses(responses: Response[], assetNames: string[]
function getStyleElementsMetadata({
includeRuntimeId,
includeCSSContent,
}: any | { includeCSSContent?: boolean; includeRuntimeId?: boolean } = {}) {
}: void | { includeCSSContent?: boolean; includeRuntimeId?: boolean } = {}) {
const styleElements = Array.from(document.head.getElementsByTagName('style'));
return styleElements.map((styleEl) => {
const data: { id?: string; depth?: string; css?: string; runtime?: string } = {
Expand Down
8 changes: 7 additions & 1 deletion packages/eslint-plugin-stylable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
"version": "5.16.0",
"description": "eslint plugin for Stylable usages",
"main": "dist/index.js",
"type": "module",
"exports": {
".": "./dist/index.js",
"./rule": "./dist/stylable-es-lint.js"
},
"scripts": {
"test": "mocha \"dist/test/**/*.spec.js\" --timeout 5000"
},
"dependencies": {
"@file-services/node": "^8.3.3",
"@stylable/core": "^5.16.0",
"@typescript-eslint/utils": "^5.61.0"
"@typescript-eslint/utils": "^6.13.1",
"postcss-safe-parser": "^7.0.0"
},
"keywords": [
"eslint",
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-plugin-stylable/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import unknownLocals from './stylable-es-lint';
import unknownLocals from './stylable-es-lint.js';

export = {
export default {
rules: {
'unknown-locals': unknownLocals,
'unknown-locals': unknownLocals as unknown,
},
configs: {
recommended: {
Expand Down
15 changes: 9 additions & 6 deletions packages/eslint-plugin-stylable/src/stylable-es-lint.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fs from '@file-services/node';
import { nodeFs as fs } from '@file-services/node';
import path from 'path';
import { Stylable, StylableMeta, createDefaultResolver } from '@stylable/core';
import { safeParse, StylableExports } from '@stylable/core/dist/index-internal';
import safeParser from 'postcss-safe-parser';
import {
ESLintUtils,
AST_NODE_TYPES,
ASTUtils,
TSESTree as esTree,
} from '@typescript-eslint/utils';
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';

const { isIdentifier } = ASTUtils;

Expand All @@ -28,8 +30,8 @@ export default createRule({
fileSystem: fs,
projectRoot: process.cwd(),
resolveModule: moduleResolver,
requireModule: require,
cssParser: safeParse,
requireModule: createRequire(pathToFileURL(process.cwd())),
cssParser: safeParser,
});

function reportDiagnostics(meta: StylableMeta, node: esTree.ImportDeclaration) {
Expand Down Expand Up @@ -68,7 +70,7 @@ export default createRule({
) as esTree.ImportSpecifier[];

namedImports.forEach(({ imported, local }) => {
const exportName = imported.name as keyof StylableExports;
const exportName = imported.name as keyof typeof exports;

if (exportName in exports) {
const variable = context.getScope().variables.find((varDefs) => {
Expand Down Expand Up @@ -127,7 +129,7 @@ export default createRule({
],
docs: {
description: '',
recommended: 'error',
recommended: 'recommended',
},
},
});
Expand All @@ -141,6 +143,7 @@ function getStylableRequest(importStatement: esTree.ImportDeclaration) {
}

function getMemberAccessor(
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
property: esTree.PrivateIdentifier | esTree.Expression,
isComputed: boolean
) {
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-plugin-stylable/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../dist"
"outDir": "../dist",
"module": "Node16" /* Specify what module code is generated. */,
"moduleResolution": "Node16"
},
"references": [{ "path": "../../core/src" }]
}
6 changes: 3 additions & 3 deletions packages/eslint-plugin-stylable/test/stylable-es-lint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path from 'path';
import fs from 'fs';
import { ESLintUtils } from '@typescript-eslint/utils';
import StylableLint from 'eslint-plugin-stylable/dist/stylable-es-lint';
import { RuleTester } from '@typescript-eslint/rule-tester';
import StylableLint from 'eslint-plugin-stylable/rule';
import { createTempDirectorySync } from '@stylable/e2e-test-kit';

// mock afterAll for RuleTester (should be fixed in next version)
(globalThis as any).afterAll = (globalThis as any).after;

const tester = new ESLintUtils.RuleTester({
const tester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-plugin-stylable/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../dist/test",
"module": "Node16" /* Specify what module code is generated. */,
"moduleResolution": "Node16",
"types": ["node", "externals", "mocha"]
},
"references": [{ "path": "../src" }, { "path": "../../e2e-test-kit/src" }]
Expand Down
12 changes: 0 additions & 12 deletions pleb.config.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
export default {
pinnedPackages: [
{
name: '@typescript-eslint/eslint-plugin',
reason: 'drop node 14 and type issues with ESLintUtils.RuleCreator',
},
{
name: '@typescript-eslint/parser',
reason: 'drop node 14 and type issues with ESLintUtils.RuleCreator',
},
{
name: '@typescript-eslint/utils',
reason: 'drop node 14 and type issues with ESLintUtils.RuleCreator',
},
{
name: 'flat',
reason: 'esm only',
Expand Down

0 comments on commit 2c441dd

Please sign in to comment.