A11yWatch/a11ywatch-core

View on GitHub

Showing 188 of 188 total issues

Function getCrawlConfig has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

export const getCrawlConfig = async ({
  id,
  role,
  url,
  tld,
Severity: Minor
Found in src/core/streams/crawl-config.ts - About 4 hrs 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

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

  if (rules && Array.isArray(rules)) {
    for (let i = 0; i < rules.length; i++) {
      const rule = rules[i];

      // validate rule storing
Severity: Major
Found in src/core/controllers/websites/set/add-website.ts and 3 other locations - About 4 hrs to fix
src/core/controllers/websites/set/add-website.ts on lines 107..119
src/web/routes/scan.ts on lines 116..129
src/web/routes/scan.ts on lines 134..146

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 119.

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 4 locations. Consider refactoring.
Open

    if (ignore && Array.isArray(ignore)) {
      for (let i = 0; i < ignore.length; i++) {
        const rule = ignore[i];
        // validate rule storing
        if (rule && typeof rule === "string" && rule.length < 200) {
Severity: Major
Found in src/web/routes/scan.ts and 3 other locations - About 4 hrs to fix
src/core/controllers/websites/set/add-website.ts on lines 89..102
src/core/controllers/websites/set/add-website.ts on lines 107..119
src/web/routes/scan.ts on lines 116..129

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 119.

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 4 locations. Consider refactoring.
Open

  if (ignore && Array.isArray(ignore)) {
    for (let i = 0; i < ignore.length; i++) {
      const rule = ignore[i];
      // validate rule storing
      if (rule && typeof rule === "string" && rule.length < 200) {
Severity: Major
Found in src/core/controllers/websites/set/add-website.ts and 3 other locations - About 4 hrs to fix
src/core/controllers/websites/set/add-website.ts on lines 89..102
src/web/routes/scan.ts on lines 116..129
src/web/routes/scan.ts on lines 134..146

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 119.

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 4 locations. Consider refactoring.
Open

    if (rules && Array.isArray(rules)) {
      for (let i = 0; i < rules.length; i++) {
        const rule = rules[i];

        // validate rule storing
Severity: Major
Found in src/web/routes/scan.ts and 3 other locations - About 4 hrs to fix
src/core/controllers/websites/set/add-website.ts on lines 89..102
src/core/controllers/websites/set/add-website.ts on lines 107..119
src/web/routes/scan.ts on lines 134..146

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 119.

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 issuesResultsTemplate has 97 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const issuesResultsTemplate: IssuesResultsFound = (
  data,
  headingElement = "h1",
  hideFooter = false,
  freeAccount = true
Severity: Major
Found in src/core/email_templates/issues-found.ts - About 3 hrs to fix

    Function stripeProductId has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const stripeProductId = (plan: string, yearly?: boolean) => {
      const q = (plan && typeof plan === "string" && plan.toUpperCase()) || "";
      let product = "";
    
      switch (q) {
    Severity: Major
    Found in src/core/utils/price-handler.ts - About 3 hrs to fix

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

        app.get("/api/pagespeed", async (req, res) => {
          const { userId, domain, pageUrl } = getBaseParams(req);
      
          await responseWrap(res, {
            callback: () =>
      Severity: Major
      Found in src/app.ts and 1 other location - About 3 hrs to fix
      src/app.ts on lines 136..148

      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 108.

      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 2 locations. Consider refactoring.
      Open

        app.get("/api/analytics", async (req, res) => {
          const { userId, domain, pageUrl } = getBaseParams(req);
      
          await responseWrap(res, {
            callback: () =>
      Severity: Major
      Found in src/app.ts and 1 other location - About 3 hrs to fix
      src/app.ts on lines 151..163

      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 108.

      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 scanAuthenticated has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const scanAuthenticated = async (
        req: FastifyContext["request"],
        res: FastifyContext["reply"]
      ) => {
        const baseUrl = paramParser(req, "websiteUrl") || paramParser(req, "url");
      Severity: Major
      Found in src/web/routes/scan.ts - About 3 hrs to fix

        Function stripeHook has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const stripeHook = async (req, res) => {
          let event: Stripe.Event;
        
          try {
            event = await stripe.webhooks.constructEventAsync(
        Severity: Major
        Found in src/web/routes_groups/stripe.ts - About 3 hrs to fix

          Function crawlHttpStream has 75 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const crawlHttpStream = (
            props: CrawlParams,
            res: FastifyContext["reply"],
            removeTrailing: boolean = true // disable for high performance output
          ): Promise<boolean> => {
          Severity: Major
          Found in src/core/utils/crawl-stream.ts - About 3 hrs to fix

            Function getReport has 70 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const getReport = async (url: string, userId?: number) => {
              if (!url) {
                return { website: undefined };
              }
              const authenticated = typeof userId !== "undefined";
            Severity: Major
            Found in src/core/controllers/reports/read.ts - About 2 hrs to fix

              Function setListRoutes has 69 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export const setListRoutes = (app: FastifyInstance) => {
                // paginated retrieve websites from the database.
                app.get("/api/list/website", async (req, res) => {
                  const { userId, offset, limit } = getBaseParamsList(req);
              
              
              Severity: Major
              Found in src/web/routes_groups/list.ts - About 2 hrs to fix

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

                  getAnalytics: async ({ userId, pageUrl }: BaseParams) => {
                    const searchProps = websiteSearchParams({ pageUrl, userId });
                
                    return validateUID(userId)
                      ? await analyticsCollection.find(searchProps).limit(20).toArray()
                Severity: Major
                Found in src/core/controllers/analytics/index.ts and 1 other location - About 2 hrs to fix
                src/core/controllers/analytics/index.ts on lines 66..72

                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 89.

                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 2 locations. Consider refactoring.
                Open

                  getWebsiteAnalytics: async ({ userId, domain }: BaseParams) => {
                    const searchProps = websiteSearchParams({ domain, userId });
                
                    return validateUID(userId)
                      ? await analyticsCollection.find(searchProps).limit(0).toArray()
                Severity: Major
                Found in src/core/controllers/analytics/index.ts and 1 other location - About 2 hrs to fix
                src/core/controllers/analytics/index.ts on lines 73..79

                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 89.

                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 setDnsVerifyRoutes has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export const setDnsVerifyRoutes = (app: FastifyInstance) => {
                  app.get("/api/website/dns", async (req, res) => {
                    const userId = validateUserRequest(req);
                
                    // check to see if dns if verified
                Severity: Major
                Found in src/web/routes_groups/dns-verify.ts - About 2 hrs to fix

                  File auth.ts has 272 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  import { request } from "https";
                  import { createUser } from "../../core/controllers/users/set";
                  import {
                    cancelSubscription,
                    runUserChecks,
                  Severity: Minor
                  Found in src/web/routes_groups/auth.ts - About 2 hrs to fix

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

                    export const crawlerCrawl = (website = {}) => {
                      return new Promise((resolve, reject) => {
                        crawlerClient.crawl(website, (error, res) => {
                          if (!error) {
                            resolve(res);
                    Severity: Major
                    Found in src/proto/actions/calls.ts and 1 other location - About 2 hrs to fix
                    src/proto/actions/calls.ts on lines 39..49

                    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 85.

                    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 2 locations. Consider refactoring.
                    Open

                    export const crawlerScan = (website = {}) => {
                      return new Promise((resolve, reject) => {
                        crawlerClient.scan(website, (error, res) => {
                          if (!error) {
                            resolve(res);
                    Severity: Major
                    Found in src/proto/actions/calls.ts and 1 other location - About 2 hrs to fix
                    src/proto/actions/calls.ts on lines 52..62

                    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 85.

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language