stoplightio/markdown

View on GitHub

Showing 69 of 69 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  it('should strip markdown out of paragraph', () => {
    const summary = getSummary(parse(`this has a [link](./foo.json)`));

    expect(summary).toBe('this has a link');
  });
Severity: Minor
Found in src/getters/__tests__/get-summary.test.ts and 2 other locations - About 40 mins to fix
src/getters/__tests__/get-summary.test.ts on lines 5..18
src/getters/__tests__/get-summary.test.ts on lines 20..31

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 48.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  it('should return frontmatter summary if present', () => {
    const summary = getSummary(
      parse(`---
summary: my summary
---
Severity: Minor
Found in src/getters/__tests__/get-summary.test.ts and 2 other locations - About 40 mins to fix
src/getters/__tests__/get-summary.test.ts on lines 20..31
src/getters/__tests__/get-summary.test.ts on lines 33..37

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 48.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function constructor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  constructor(data: MDAST.Root | string, mutate = false) {
    const root =
      typeof data === 'string' ? parseWithPointers(data).data : mutate ? data : JSON.parse(JSON.stringify(data));
    if (root.type !== 'root') {
      throw new TypeError('Malformed yaml was provided');
Severity: Minor
Found in src/frontmatter/frontmatter.ts - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function unwrapImages has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export const unwrapImages: unified.Attacher = function () {
  // Patch slugs on heading nodes.
  return function transformer(tree) {
    visit<Parent>(tree, 'paragraph', (node, index, parent) => {
      if (!index) return;
Severity: Minor
Found in src/plugins/run/unwrap-images.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getTags has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export const getTags = (data?: MDAST.Root): string[] => {
  const tags: string[] = [];

  if (data) {
    try {
Severity: Minor
Found in src/getters/get-tags.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function handleLegacyAnnotations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function handleLegacyAnnotations(annotations: MDAST.Code['annotations']) {
  if (!annotations) return;

  if (annotations.hasOwnProperty('type')) {
    // @ts-expect-error type is no longer part of the typings, it is deprecated
Severity: Minor
Found in src/plugins/run/code.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function updateDocument has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  private updateDocument() {
    const children = this.document.children as MDAST.Parent['children'] | undefined;
    if (!children) return;

    const index = children.indexOf(this.node);
Severity: Minor
Found in src/frontmatter/frontmatter.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function inlineImages has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export const inlineImages: unified.Attacher = function () {
  // Set `inline` prop on images that we consider "inline", so that downstream renderers can render them nicely
  return function transformer(tree) {
    visit<Parent>(tree, ['image', 'imageReference'], (node, index, parent) => {
      if (!parent) return;
Severity: Minor
Found in src/plugins/run/inline-images.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function parseMeta has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function parseMeta(metastring?: string | null) {
  const props: Record<string, boolean | string> = {};

  if (!metastring) return props;

Severity: Minor
Found in src/plugins/run/code.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Severity
Category
Status
Source
Language