Skip to content

Commit

Permalink
feature: redput: parseComment: ^[a-z-]$: avoid any parsing use as is
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 14, 2024
1 parent 4ec8921 commit 33feb59
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/parse-plugin/parse-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function parseComment(comment) {
.replace('//', '')
.trimStart();

if (/^[a-z-]+$/.test(raw))
return ['', raw];

const [error, data] = tryCatch(JSON.parse, raw);

if (!error)
Expand Down
12 changes: 12 additions & 0 deletions lib/parse-plugin/parse-plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ test('redput: parse-plugin: lines', (t) => {
t.end();
});

test('redput: parse-plugin: comment: -', (t) => {
const {name} = parsePlugin(montag`
// remove-quotes-from-import-assertions
export const report = () => 'hello';
`);

const expected = 'remove-quotes-from-import-assertions';

t.equal(name, expected);
t.end();
});

test('redput: parse-plugin: lines: name: disabled', (t) => {
const {name} = parsePlugin(montag`
// ["off", "hello.js"]
Expand Down
2 changes: 1 addition & 1 deletion lib/read-gist/read-gist.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {test} from 'supertape';
import {readGist} from './read-gist.js';
import tryToCatch from 'try-to-catch';
import {readGist} from './read-gist.js';

test('redput: readGist', async (t) => {
const hash = '/33a75dce299788583a567e02f29828c8/7a97049f1c88ef9e3396d43b6a64246da0093670';
Expand Down
2 changes: 1 addition & 1 deletion lib/write/nested/add-rule/add-rule.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import putout from 'putout';
import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';
import pluginPutout from '@putout/plugin-putout';
import nodejs from '@putout/plugin-nodejs';
import removeUnusedVariables from '@putout/plugin-remove-unused-variables';
import * as insertGetRulePlugin from './plugin-insert-get-rule/index.js';

export const addRule = (name, source, ruleOptions) => {
const {code} = putout(source, {
Expand Down
2 changes: 1 addition & 1 deletion lib/write/nested/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
dirname,
join,
} from 'node:path';
import rendy from 'rendy';
import process from 'node:process';
import rendy from 'rendy';
import {addRule} from './add-rule/add-rule.js';
import {insertTest} from './insert-test/insert-test.js';
import {prepareRule} from './prepare-rule/prepare-rule.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/write/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
dirname,
join,
} from 'node:path';
import rendy from 'rendy';
import process from 'node:process';
import rendy from 'rendy';

export const writeRule = async (name, data) => {
await mkdir(`./lib`, {
Expand Down

0 comments on commit 33feb59

Please sign in to comment.