eslint-plugin-frontmatter2 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ <!-- markdownlint-disable -->
2
+ # Changelog
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [v1.0.0] - 2024-04-15
11
+
12
+ Initial Release
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Chris Zuber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # eslint-plugin-frontmatter2
2
+
3
+ Plugin to allow YAML frontmatter to be ignored by ESLint
4
+
5
+ [![CodeQL](https://github.com/shgysk8zer0/eslint-frontmatter/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/shgysk8zer0/eslint-frontmatter/actions/workflows/codeql-analysis.yml)
6
+ ![Node CI](https://github.com/shgysk8zer0/eslint-frontmatter/workflows/Node%20CI/badge.svg)
7
+ ![Lint Code Base](https://github.com/shgysk8zer0/eslint-frontmatter/workflows/Lint%20Code%20Base/badge.svg)
8
+
9
+ [![GitHub license](https://img.shields.io/github/license/shgysk8zer0/eslint-frontmatter.svg)](https://github.com/shgysk8zer0/eslint-frontmatter/blob/master/LICENSE)
10
+ [![GitHub last commit](https://img.shields.io/github/last-commit/shgysk8zer0/eslint-frontmatter.svg)](https://github.com/shgysk8zer0/eslint-frontmatter/commits/master)
11
+ [![GitHub release](https://img.shields.io/github/release/shgysk8zer0/eslint-frontmatter?logo=github)](https://github.com/shgysk8zer0/eslint-frontmatter/releases)
12
+ [![GitHub Sponsors](https://img.shields.io/github/sponsors/shgysk8zer0?logo=github)](https://github.com/sponsors/shgysk8zer0)
13
+
14
+ [![npm](https://img.shields.io/npm/v/eslint-plugin-frontmatter2)](https://www.npmjs.com/package/eslint-plugin-frontmatter2)
15
+ ![node-current](https://img.shields.io/node/v/eslint-plugin-frontmatter2)
16
+ ![npm bundle size gzipped](https://img.shields.io/bundlephobia/minzip/eslint-plugin-frontmatter2)
17
+ [![npm](https://img.shields.io/npm/dw/eslint-plugin-frontmatter2?logo=npm)](https://www.npmjs.com/package/eslint-plugin-frontmatter2)
18
+
19
+ [![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)](https://github.com/shgysk8zer0)
20
+ ![GitHub forks](https://img.shields.io/github/forks/shgysk8zer0/eslint-frontmatter.svg?style=social)
21
+ ![GitHub stars](https://img.shields.io/github/stars/shgysk8zer0/eslint-frontmatter.svg?style=social)
22
+ [![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)](https://twitter.com/shgysk8zer0)
23
+
24
+ [![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate "Donate using Liberapay")
25
+ - - -
26
+
27
+ - [Code of Conduct](./.github/CODE_OF_CONDUCT.md)
28
+ - [Contributing](./.github/CONTRIBUTING.md)
29
+ <!-- - [Security Policy](./.github/SECURITY.md) -->
30
+
31
+ ```js
32
+ ---
33
+ foo: bar
34
+ number: 42
35
+ works: true
36
+ person:
37
+ name: Chris
38
+ age: 38
39
+ developer: true
40
+ ---
41
+
42
+ console.log('{{ foo }}');
43
+ console.log(JSON.parse('{{ person | jsonify }}'));
44
+ ```
45
+
46
+ > [!IMPORTANT]
47
+ > This plugin does not enable Liquid templating support in JavaScript. For this
48
+ > reason, it is advised that you enclose all such variables in quotes and treat
49
+ > them as strings, eg. `foo('{{ bar }}')`. You may use `parseInt` or `JSON.parse`
50
+ > as necessary from there.
51
+
52
+ ## Example Config File
53
+
54
+ ```js
55
+ import frontmatter from 'eslint-plugin-frontmatter2';
56
+
57
+ export default {
58
+ 'plugins': {
59
+ 'frontmatter2': frontmatter
60
+ },
61
+ processor: 'frontmatter/frontmatter',
62
+ };
63
+ ```
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "eslint-plugin-frontmatter2",
3
+ "version": "1.0.0",
4
+ "description": "Plugin to allow YAML frontmatter to be ignored by ESLint",
5
+ "keywords": [
6
+ "eslint",
7
+ "eslint-plugin",
8
+ "eslint-frontmatter",
9
+ "eslint-plugin-frontmatter",
10
+ "frontmatter",
11
+ "jekyll",
12
+ "liguid",
13
+ "eleventy",
14
+ "11ty"
15
+ ],
16
+ "type": "module",
17
+ "main": "./plugin.cjs",
18
+ "module": "./plugin.mjs",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./plugin.mjs",
22
+ "require": "./plugin.cjs"
23
+ },
24
+ "./*.js": {
25
+ "import": "./*.mjs",
26
+ "require": "./*.cjs"
27
+ },
28
+ "./*.mjs": {
29
+ "import": "./*.mjs",
30
+ "require": "./*.cjs"
31
+ },
32
+ "./*.cjs": {
33
+ "import": "./*.mjs",
34
+ "require": "./*.cjs"
35
+ },
36
+ "./*": {
37
+ "import": "./*.mjs",
38
+ "require": "./*.cjs"
39
+ }
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "private": false,
45
+ "scripts": {
46
+ "test": "npm run lint:js && npm run build",
47
+ "preversion": "npm test",
48
+ "prepare": "npm run build",
49
+ "lint:js": "eslint .",
50
+ "fix:js": "eslint . --fix",
51
+ "build": "npm run build:js",
52
+ "clean": "rm -f ./*.cjs && rm -f ./*.mjs",
53
+ "build:js": "npm run clean && rollup -c rollup.config.js",
54
+ "create:lock": "npm i --package-lock-only --ignore-scripts --no-audit --no-fund",
55
+ "version:bump": "npm run version:bump:patch",
56
+ "version:bump:patch": "npm version --no-git-tag-version patch && npm run create:lock",
57
+ "version:bump:minor": "npm version --no-git-tag-version minor && npm run create:lock",
58
+ "version:bump:major": "npm version --no-git-tag-version major && npm run create:lock"
59
+ },
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git+https://github.com/shgysk8zer0/eslint-frontmatter.git"
63
+ },
64
+ "author": "Chris Zuber <admin@kernvalley.us>",
65
+ "license": "MIT",
66
+ "funding": [
67
+ {
68
+ "type": "librepay",
69
+ "url": "https://liberapay.com/shgysk8zer0"
70
+ },
71
+ {
72
+ "type": "github",
73
+ "url": "https://github.com/sponsors/shgysk8zer0"
74
+ }
75
+ ],
76
+ "bugs": {
77
+ "url": "https://github.com/shgysk8zer0/eslint-frontmatter/issues"
78
+ },
79
+ "homepage": "https://github.com/shgysk8zer0/eslint-frontmatter#readme",
80
+ "devDependencies": {
81
+ "@rollup/plugin-json": "^6.1.0",
82
+ "eslint": "^9.0.0",
83
+ "rollup": "^4.14.3"
84
+ }
85
+ }
package/plugin.cjs ADDED
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ var name = "eslint-plugin-frontmatter2";
4
+ var version = "1.0.0";
5
+
6
+ // Import from module since import attributes not yet supported
7
+
8
+ const map = new Map();
9
+
10
+ /**
11
+ * @see https://eslint.org/docs/latest/extend/custom-processors#custom-processor-specification
12
+ */
13
+ const frontmatter = {
14
+ meta: { name, version },
15
+ processors: {
16
+ 'frontmatter': {
17
+ meta: {
18
+ // Must begin with 'eslint-'
19
+ name: 'eslint-frontmatter',
20
+ version,
21
+ },
22
+
23
+ /**
24
+ * Strips out frontmatter before linting
25
+ */
26
+ preprocess(text, filename) {
27
+ if (text.startsWith('---')) {
28
+ // Trim out opening of frontmatter ('---\n')
29
+ const trimmed = text.substring(4);
30
+ // Find index of closing of frontmatter & add 4 for '---\n'
31
+ const end = trimmed.search(/^---$/m) + 4;
32
+
33
+ if (end > 3) {
34
+ // Count number of newlines in frontmatter section
35
+ const newlines = text.substring(0, end).match(/[\r\n]{1}/g);
36
+ // Save number of newlines for `postprocess`
37
+ map.set(filename, newlines.length + 1);
38
+ return [{ text: trimmed.substring(end), filename }];
39
+ } else {
40
+ return [{ text, filename }];
41
+ }
42
+ } else {
43
+ return [{ text, filename }];
44
+ }
45
+ },
46
+
47
+ /**
48
+ * Adjust line numbers in errors to correct for stripped frontmatter
49
+ */
50
+ postprocess(messages, filename) {
51
+ if (map.has(filename)) {
52
+ const offset = map.get(filename);
53
+ return messages.flatMap(
54
+ errs => errs.map(({ line, ...rest }) => ({ line: line + offset, ...rest}))
55
+ );
56
+ } else {
57
+ return messages.flat();
58
+ }
59
+ },
60
+ supportsAutofix: false,
61
+ }
62
+ }
63
+ };
64
+
65
+ exports.frontmatter = frontmatter;
package/plugin.mjs ADDED
@@ -0,0 +1,63 @@
1
+ var name = "eslint-plugin-frontmatter2";
2
+ var version = "1.0.0";
3
+
4
+ // Import from module since import attributes not yet supported
5
+
6
+ const map = new Map();
7
+
8
+ /**
9
+ * @see https://eslint.org/docs/latest/extend/custom-processors#custom-processor-specification
10
+ */
11
+ const frontmatter = {
12
+ meta: { name, version },
13
+ processors: {
14
+ 'frontmatter': {
15
+ meta: {
16
+ // Must begin with 'eslint-'
17
+ name: 'eslint-frontmatter',
18
+ version,
19
+ },
20
+
21
+ /**
22
+ * Strips out frontmatter before linting
23
+ */
24
+ preprocess(text, filename) {
25
+ if (text.startsWith('---')) {
26
+ // Trim out opening of frontmatter ('---\n')
27
+ const trimmed = text.substring(4);
28
+ // Find index of closing of frontmatter & add 4 for '---\n'
29
+ const end = trimmed.search(/^---$/m) + 4;
30
+
31
+ if (end > 3) {
32
+ // Count number of newlines in frontmatter section
33
+ const newlines = text.substring(0, end).match(/[\r\n]{1}/g);
34
+ // Save number of newlines for `postprocess`
35
+ map.set(filename, newlines.length + 1);
36
+ return [{ text: trimmed.substring(end), filename }];
37
+ } else {
38
+ return [{ text, filename }];
39
+ }
40
+ } else {
41
+ return [{ text, filename }];
42
+ }
43
+ },
44
+
45
+ /**
46
+ * Adjust line numbers in errors to correct for stripped frontmatter
47
+ */
48
+ postprocess(messages, filename) {
49
+ if (map.has(filename)) {
50
+ const offset = map.get(filename);
51
+ return messages.flatMap(
52
+ errs => errs.map(({ line, ...rest }) => ({ line: line + offset, ...rest}))
53
+ );
54
+ } else {
55
+ return messages.flat();
56
+ }
57
+ },
58
+ supportsAutofix: false,
59
+ }
60
+ }
61
+ };
62
+
63
+ export { frontmatter };