JaneJeon/myURL

View on GitHub

Showing 41 of 42 total issues

Function LinkShortener has 163 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function LinkShortener() {
  const [isOpen, setIsOpen] = useState(false)
  const notify = useNotify()
  const {
    loading: permissionsLoading,
Severity: Major
Found in src/components/shortener.js - About 6 hrs to fix

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

    exports.long = rateLimit({
      legacyHeaders: true,
      windowMs: ms(process.env.RATE_LIMIT_LONG_WINDOW),
      max: process.env.RATE_LIMIT_LONG_MAX - 0,
      keyGenerator: req =>
    Severity: Major
    Found in middlewares/rate-limiter.js and 1 other location - About 4 hrs to fix
    middlewares/rate-limiter.js on lines 9..19

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

    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

    exports.short = rateLimit({
      legacyHeaders: true,
      windowMs: ms(process.env.RATE_LIMIT_SHORT_WINDOW),
      max: process.env.RATE_LIMIT_SHORT_MAX - 0,
      keyGenerator: req =>
    Severity: Major
    Found in middlewares/rate-limiter.js and 1 other location - About 4 hrs to fix
    middlewares/rate-limiter.js on lines 21..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 122.

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

    const EditComponent = props => {
      const { loading, permissions } = usePermissions()
      const resource = subject('Link', props.record)
    
      return loading ? (
    Severity: Major
    Found in src/resources/link.js - About 4 hrs to fix

      Function QueryBuilder has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

        static get QueryBuilder() {
          return class extends super.QueryBuilder {
            insertAndFetch(body) {
              const q = this.insert(body).returning('*')
              return Array.isArray(body) ? q : q.first()
      Severity: Minor
      Found in models/base.js - 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 2 locations. Consider refactoring.
      Open

              <Resource
                name="links"
                options={{ label: 'Links' }}
                icon={LinkIcon}
                list={permissions.can('read', 'Link') ? link.List : null}
      Severity: Major
      Found in src/App.js and 1 other location - About 3 hrs to fix
      src/App.js on lines 70..77

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

      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

              <Resource
                name="users"
                options={{ label: 'Users' }}
                icon={PeopleIcon}
                list={permissions.can('read', 'User') ? user.List : null}
      Severity: Major
      Found in src/App.js and 1 other location - About 3 hrs to fix
      src/App.js on lines 62..69

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

      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

      module.exports = Router()
        // When "creating" a link, the user is trying to shorten a link.
        // Now, we *could* just throw a 409 when there's a duplicate link,
        // but when we say "oh someone else already shortened that link",
        // the user is going to want to see it anyway, so we skip the back-and-forth
      Severity: Major
      Found in routes/api/links.js and 1 other location - About 3 hrs to fix
      routes/api/users.js on lines 5..13

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

      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

      module.exports = Router()
        .get('/', requireScope('user:read'), async (req, res) => {
          const { total, results } = await User.query()
            .paginate(req.query)
            .authorize(req.user)
      Severity: Major
      Found in routes/api/users.js and 1 other location - About 3 hrs to fix
      routes/api/links.js on lines 6..40

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

      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 verify has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      exports.verify = (scopeStr, requiredScope) => {
        return scopeStr.split(' ').some(scope => {
          if (scope.includes('*')) {
            // There's a * to expand; given that each section is separated by a colon,
            // try to expand it and see if it fits
      Severity: Minor
      Found in lib/scope.js - About 2 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

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

        beforeAll(async () => {
          await User.query().findById(TEST_SUPERUSER_ID).delete()
          await User.query().insert({
            id: TEST_SUPERUSER_ID,
            role: 'superuser',
      Severity: Major
      Found in routes/api/links.test.js and 1 other location - About 2 hrs to fix
      models/link.test.js on lines 11..19

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

      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

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

        beforeAll(async () => {
          await User.query().findById(TEST_SUPERUSER_ID).delete()
          await User.query().insert({
            id: TEST_SUPERUSER_ID,
            role: 'superuser',
      Severity: Major
      Found in models/link.test.js and 1 other location - About 2 hrs to fix
      routes/api/links.test.js on lines 19..27

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

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

        static get QueryBuilder() {
          return class extends super.QueryBuilder {
            insertAndFetch(body) {
              const q = this.insert(body).returning('*')
              return Array.isArray(body) ? q : q.first()
      Severity: Minor
      Found in models/base.js - About 1 hr to fix

        Function App has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function App() {
          // theme that changes to dark mode according to system settings
          const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)')
          const theme = useMemo(
            () =>
        Severity: Minor
        Found in src/App.js - About 1 hr to fix

          Function EditComponent has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const EditComponent = props => {
            const { loading, permissions } = usePermissions()
            const resource = subject('User', props.record)
          
            return loading ? (
          Severity: Minor
          Found in src/resources/user.js - About 1 hr to fix

            Function seed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            exports.seed = async knex => {
              option({ random: require('seedrandom')('Some seed') })
            
              const links = []
              const schema = deepCopy(globalSchema.Link)
            Severity: Minor
            Found in seeds/20210312221718_links.js - About 1 hr 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 exports has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = (err, req, res, next) => {
              if (res.headersSent) {
                req.log.error(err, 'An error occurred after request was sent')
                return
              }
            Severity: Minor
            Found in middlewares/error-handler.js - About 1 hr to fix

              Function $parseJson has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                $parseJson(originalJSON, opt) {
                  const json = deepCopy(super.$parseJson(originalJSON, opt))
              
                  if (json.hash) {
                    // Since custom and auto-generated hash are both mounted under /,
              Severity: Minor
              Found in models/link.js - About 1 hr 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 2 locations. Consider refactoring.
              Open

                  await expect(
                    Link.query().insert({
                      originalUrl: originalUrls[2],
                      hash: generatedHash,
                      creatorId: user.id
              Severity: Major
              Found in models/link.test.js and 1 other location - About 1 hr to fix
              models/link.test.js on lines 95..101

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

              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

                  await expect(
                    Link.query().insert({
                      originalUrl: originalUrls[2],
                      hash,
                      creatorId: user.id
              Severity: Major
              Found in models/link.test.js and 1 other location - About 1 hr to fix
              models/link.test.js on lines 106..112

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

              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