From 076a443dfe86c0b9f1f573ed15bd44a643e0c812 Mon Sep 17 00:00:00 2001 From: mmkal Date: Wed, 7 Oct 2020 17:38:30 -0400 Subject: [PATCH 1/2] fix: trim empty lines this prevents an interaction with other lint rules which expect newlines at the end of the file --- packages/eslint-plugin-codegen/src/__tests__/plugin.test.ts | 6 +++--- packages/eslint-plugin-codegen/src/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin-codegen/src/__tests__/plugin.test.ts b/packages/eslint-plugin-codegen/src/__tests__/plugin.test.ts index 9c1d51de..fa85ab7e 100644 --- a/packages/eslint-plugin-codegen/src/__tests__/plugin.test.ts +++ b/packages/eslint-plugin-codegen/src/__tests__/plugin.test.ts @@ -24,11 +24,11 @@ describe('markdown processor', () => { Array [ "/* eslint-disable prettier/prettier */ // eslint-plugin-codegen:remove // eslint-plugin-codegen:trim# Title - // eslint-plugin-codegen:trim + // eslint-plugin-codegen:trim - // eslint-plugin-codegen:trim + // eslint-plugin-codegen:trim
html
- // eslint-plugin-codegen:trim + // eslint-plugin-codegen:trim\`\`\`js // eslint-plugin-codegen:trim// some javascript // eslint-plugin-codegen:trimconst x = 1 diff --git a/packages/eslint-plugin-codegen/src/index.ts b/packages/eslint-plugin-codegen/src/index.ts index 11d436a2..83dd853c 100644 --- a/packages/eslint-plugin-codegen/src/index.ts +++ b/packages/eslint-plugin-codegen/src/index.ts @@ -21,7 +21,7 @@ const getPreprocessor = (): eslint.Linter.LintOptions => { os.EOL + text .split(/\r?\n/) - .map(line => `// eslint-plugin-codegen:trim${line}`) + .map(line => line && `// eslint-plugin-codegen:trim${line}`) .join(os.EOL), ], postprocess: messageLists => ([] as eslint.Linter.LintMessage[]).concat(...messageLists), @@ -109,7 +109,7 @@ const codegen: eslint.Rule.RuleModule = { const opts = maybeOptions.right || {} const presets: Record | undefined> = { ...presetsModule, - ...context.options?.[0]?.presets, + ...context.options[0]?.presets, } const preset = typeof opts?.preset === 'string' && presets[opts.preset] if (typeof preset !== 'function') { From 7a9d9e8892c2cba96e83693e2909d48b8110f9bc Mon Sep 17 00:00:00 2001 From: mmkal Date: Mon, 12 Oct 2020 12:07:54 +0000 Subject: [PATCH 2/2] chore: change files --- .../codegen-trim-empty-lines_pr-201.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/eslint-plugin-codegen/codegen-trim-empty-lines_pr-201.json diff --git a/common/changes/eslint-plugin-codegen/codegen-trim-empty-lines_pr-201.json b/common/changes/eslint-plugin-codegen/codegen-trim-empty-lines_pr-201.json new file mode 100644 index 00000000..3c4f390c --- /dev/null +++ b/common/changes/eslint-plugin-codegen/codegen-trim-empty-lines_pr-201.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: trim empty lines (#201)", + "type": "patch", + "packageName": "eslint-plugin-codegen" + } + ], + "packageName": "eslint-plugin-codegen", + "email": "mmkal@users.noreply.github.com" +} \ No newline at end of file