@react-pug/eslint-plugin-react-pug 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/package.json +20 -0
- package/tsconfig.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @react-pug/eslint-plugin-react-pug
|
|
2
|
+
|
|
3
|
+
ESLint processor for linting files that contain `pug\`...\`` tagged template literals.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D @react-pug/eslint-plugin-react-pug eslint
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import reactPugPlugin from '@react-pug/eslint-plugin-react-pug'
|
|
15
|
+
|
|
16
|
+
export default [
|
|
17
|
+
{
|
|
18
|
+
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
19
|
+
plugins: { 'react-pug': reactPugPlugin },
|
|
20
|
+
processor: 'react-pug/pug-react'
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Options
|
|
26
|
+
|
|
27
|
+
Use `createReactPugProcessor(...)` when you need custom options:
|
|
28
|
+
|
|
29
|
+
- `tagFunction`
|
|
30
|
+
- `requirePugImport`
|
|
31
|
+
- `classShorthandProperty`
|
|
32
|
+
- `classShorthandMerge`
|
|
33
|
+
- `startupjsCssxjs`
|
|
34
|
+
- `componentPathFromUppercaseClassShorthand`
|
|
35
|
+
|
|
36
|
+
Used `pug` import bindings are removed from the processor's transformed view automatically.
|
|
37
|
+
|
|
38
|
+
## Exports
|
|
39
|
+
|
|
40
|
+
- default ESLint plugin object
|
|
41
|
+
- `createReactPugProcessor(...)`
|
|
42
|
+
|
|
43
|
+
Published output is in `dist/`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ClassAttributeOption, type ClassMergeOption, type StartupjsCssxjsOption } from '@react-pug/react-pug-core';
|
|
2
|
+
export interface EslintReactPugProcessorOptions {
|
|
3
|
+
tagFunction?: string;
|
|
4
|
+
requirePugImport?: boolean;
|
|
5
|
+
classShorthandProperty?: ClassAttributeOption;
|
|
6
|
+
classShorthandMerge?: ClassMergeOption;
|
|
7
|
+
startupjsCssxjs?: StartupjsCssxjsOption;
|
|
8
|
+
componentPathFromUppercaseClassShorthand?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface EslintLintMessage {
|
|
11
|
+
line?: number;
|
|
12
|
+
column?: number;
|
|
13
|
+
endLine?: number;
|
|
14
|
+
endColumn?: number;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface EslintProcessorLike {
|
|
18
|
+
preprocess: (text: string, filename: string) => string[];
|
|
19
|
+
postprocess: (messages: EslintLintMessage[][], filename: string) => EslintLintMessage[];
|
|
20
|
+
supportsAutofix: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function createReactPugProcessor(options?: EslintReactPugProcessorOptions): EslintProcessorLike;
|
|
23
|
+
declare const plugin: {
|
|
24
|
+
processors: {
|
|
25
|
+
'pug-react': EslintProcessorLike;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export default plugin;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAIrB,KAAK,qBAAqB,EAE3B,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,8BAA8B;IAC7C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,oBAAoB,CAAC;IAC9C,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IACvC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,wCAAwC,CAAC,EAAE,OAAO,CAAC;CACpD;AAED,UAAU,iBAAiB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAID,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IACzD,WAAW,EAAE,CAAC,QAAQ,EAAE,iBAAiB,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,KAAK,iBAAiB,EAAE,CAAC;IACxF,eAAe,EAAE,OAAO,CAAC;CAC1B;AAiCD,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,8BAAmC,GAC3C,mBAAmB,CA+BrB;AAID,QAAA,MAAM,MAAM;;;;CAIX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createReactPugProcessor = createReactPugProcessor;
|
|
4
|
+
const react_pug_core_1 = require("@react-pug/react-pug-core");
|
|
5
|
+
function mapLintMessage(message, transformed) {
|
|
6
|
+
if (message.line == null || message.column == null)
|
|
7
|
+
return message;
|
|
8
|
+
const generatedStart = (0, react_pug_core_1.lineColumnToOffset)(transformed.code, message.line, message.column);
|
|
9
|
+
const generatedEnd = (message.endLine != null && message.endColumn != null)
|
|
10
|
+
? (0, react_pug_core_1.lineColumnToOffset)(transformed.code, message.endLine, message.endColumn)
|
|
11
|
+
: generatedStart + 1;
|
|
12
|
+
const mapped = (0, react_pug_core_1.mapGeneratedRangeToOriginal)(transformed.document, generatedStart, Math.max(1, generatedEnd - generatedStart));
|
|
13
|
+
if (!mapped)
|
|
14
|
+
return message;
|
|
15
|
+
const startLc = (0, react_pug_core_1.offsetToLineColumn)(transformed.document.originalText, mapped.start);
|
|
16
|
+
const endLc = (0, react_pug_core_1.offsetToLineColumn)(transformed.document.originalText, mapped.end);
|
|
17
|
+
return {
|
|
18
|
+
...message,
|
|
19
|
+
line: startLc.line,
|
|
20
|
+
column: startLc.column,
|
|
21
|
+
endLine: endLc.line,
|
|
22
|
+
endColumn: endLc.column,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createReactPugProcessor(options = {}) {
|
|
26
|
+
const cache = new Map();
|
|
27
|
+
return {
|
|
28
|
+
preprocess(text, filename) {
|
|
29
|
+
const transformed = (0, react_pug_core_1.transformSourceFile)(text, filename, {
|
|
30
|
+
tagFunction: options.tagFunction ?? 'pug',
|
|
31
|
+
compileMode: 'runtime',
|
|
32
|
+
requirePugImport: options.requirePugImport ?? false,
|
|
33
|
+
classAttribute: options.classShorthandProperty ?? 'auto',
|
|
34
|
+
classMerge: options.classShorthandMerge ?? 'auto',
|
|
35
|
+
startupjsCssxjs: options.startupjsCssxjs ?? 'auto',
|
|
36
|
+
componentPathFromUppercaseClassShorthand: options.componentPathFromUppercaseClassShorthand ?? true,
|
|
37
|
+
});
|
|
38
|
+
cache.set(filename, transformed);
|
|
39
|
+
return [transformed.code];
|
|
40
|
+
},
|
|
41
|
+
postprocess(messages, filename) {
|
|
42
|
+
const transformed = cache.get(filename);
|
|
43
|
+
cache.delete(filename);
|
|
44
|
+
const flat = messages.flat();
|
|
45
|
+
if (!transformed)
|
|
46
|
+
return flat;
|
|
47
|
+
if (transformed.regions.length === 0)
|
|
48
|
+
return flat;
|
|
49
|
+
return flat.map((msg) => mapLintMessage(msg, transformed));
|
|
50
|
+
},
|
|
51
|
+
supportsAutofix: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const defaultProcessor = createReactPugProcessor();
|
|
55
|
+
const plugin = {
|
|
56
|
+
processors: {
|
|
57
|
+
'pug-react': defaultProcessor,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
exports.default = plugin;
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAkEA,0DAiCC;AAnGD,8DAQmC;AA2BnC,SAAS,cAAc,CACrB,OAA0B,EAC1B,WAAiC;IAEjC,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC;IAEnE,MAAM,cAAc,GAAG,IAAA,mCAAkB,EAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1F,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;QACzE,CAAC,CAAC,IAAA,mCAAkB,EAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;QAC1E,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC;IAEvB,MAAM,MAAM,GAAG,IAAA,4CAA2B,EACxC,WAAW,CAAC,QAAQ,EACpB,cAAc,EACd,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,CAC3C,CAAC;IAEF,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAE5B,MAAM,OAAO,GAAG,IAAA,mCAAkB,EAAC,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACpF,MAAM,KA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AI,CAAC;YAC9B,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAElD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,eAAe,EAAE,IAAI;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;AAEnD,MAAM,MAAM,GAAG;IACb,UAAU,EAAE;QACV,WAAW,EAAE,gBAAgB;KAC9B;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-pug/eslint-plugin-react-pug",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "npm --prefix ../.. run build -w @react-pug/react-pug-core && rm -rf dist && tsc -p tsconfig.build.json",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@react-pug/react-pug-core": "^0.1.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"eslint": "^9.0.0"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "b4e9f09659dd4c70d0734759ea00710414fd8366"
|
|
20
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": true,
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"paths": {
|
|
7
|
+
"@react-pug/react-pug-core": [
|
|
8
|
+
"../react-pug-core/src/index.ts"
|
|
9
|
+
]
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*.ts"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"dist"
|
|
17
|
+
]
|
|
18
|
+
}
|