anyone-oslo/pages

View on GitHub

Showing 130 of 130 total issues

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

function getFiles(dt: DataTransfer): File[] {
  const files: File[] = [];
  if (dt.items) {
    for (let i = 0; i < dt.items.length; i++) {
      if (dt.items[i].kind == "file") {
Severity: Major
Found in app/javascript/components/ImageUploader.tsx and 1 other location - About 7 hrs to fix
app/javascript/components/drag/useDragUploader.ts on lines 34..48

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

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

function getFiles(dt: DataTransfer): File[] {
  const files: File[] = [];
  if (dt.items) {
    for (let i = 0; i < dt.items.length; i++) {
      if (dt.items[i].kind == "file") {
Severity: Major
Found in app/javascript/components/drag/useDragUploader.ts and 1 other location - About 7 hrs to fix
app/javascript/components/ImageUploader.tsx on lines 28..42

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

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

export default function Grid(props: Props) {
  const { primary, images, deleted, setDeleted } = props.state;

  const containerRef = useRef();
  const error = useToastStore((state) => state.error);
Severity: Major
Found in app/javascript/components/ImageGrid/Grid.tsx - About 7 hrs to fix

    Function PageTree has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function PageTree({ dir, locale, pages, permissions }: Props) {
      const [state, dispatch] = usePageTree(pages, locale, dir, permissions);
    
      const [dragging, setDragging] = useState(false);
      const [dragState, setDragState] = useState<DragState | null>(null);
    Severity: Minor
    Found in app/javascript/components/PageTree.tsx - About 5 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

    Function ImageUploader has 132 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export default function ImageUploader(props: Props) {
      const [uploading, setUploading] = useState(false);
      const [dragover, setDragover] = useState(false);
      const [state, setState] = useState<State>({
        image: props.image,
    Severity: Major
    Found in app/javascript/components/ImageUploader.tsx - About 5 hrs to fix

      Function Node has 127 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export default function Node(props: Props) {
        const { state, dispatch } = usePageTreeContext();
        const { id, dragging, onDragStart } = props;
        const { dir, locale } = state;
        const node = state.nodes[id];
      Severity: Major
      Found in app/javascript/components/PageTree/Node.tsx - About 5 hrs to fix

        Function PageForm has 122 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function PageForm(props: Props) {
          const [state, dispatch] = usePage({
            locales: props.locales,
            locale: props.locale,
            page: props.page,
        Severity: Major
        Found in app/javascript/components/PageForm.tsx - About 4 hrs to fix

          Function List has 121 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function List(props: Props) {
            const { collection, deleted, setDeleted } = props.state;
            const locales = props.locales ? Object.keys(props.locales) : [props.locale];
          
            const uploadAttachment = (file: File) => {
          Severity: Major
          Found in app/javascript/components/Attachments/List.tsx - About 4 hrs to fix

            Function Attachment has 98 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export default function Attachment(props: Props) {
              const { attributeName, draggable, locales, locale } = props;
              const { record } = draggable;
              const { attachment, uploading } = record;
            
            
            Severity: Major
            Found in app/javascript/components/Attachments/Attachment.tsx - About 3 hrs to fix

              Function ImageUploader has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
              Open

              export default function ImageUploader(props: Props) {
                const [uploading, setUploading] = useState(false);
                const [dragover, setDragover] = useState(false);
                const [state, setState] = useState<State>({
                  image: props.image,
              Severity: Minor
              Found in app/javascript/components/ImageUploader.tsx - About 3 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

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

              export default function AttachmentEditor(props: Props) {
                const { attachment, locales } = props;
              
                const [locale, setLocale] = useState(props.locale);
                const [localizations, setLocalizations] = useState({
              Severity: Major
              Found in app/javascript/components/Attachments/AttachmentEditor.tsx - About 3 hrs to fix

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

                export default function Images(props: Props) {
                  return (
                    <div className="page-images">
                      <Grid
                        attribute="page[page_images_attributes]"
                Severity: Major
                Found in app/javascript/components/PageForm/Images.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/PageImages.tsx on lines 12..26

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

                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 default function PageImages(props: Props) {
                  return (
                    <div className="page-images">
                      <ImageGrid
                        attribute="page[page_images_attributes]"
                Severity: Major
                Found in app/javascript/components/PageImages.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/PageForm/Images.tsx on lines 12..26

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

                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

                      {templateConfig.metadata_blocks.map((b) => (
                        <Block
                          key={b.name}
                          block={b}
                          errors={errorsOn(page, b.name)}
                Severity: Major
                Found in app/javascript/components/PageForm/Metadata.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/PageForm/Content.tsx on lines 27..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 100.

                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

                      {templateConfig.blocks.map((b) => (
                        <Block
                          key={b.name}
                          block={b}
                          errors={errorsOn(page, b.name)}
                Severity: Major
                Found in app/javascript/components/PageForm/Content.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/PageForm/Metadata.tsx on lines 49..59

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

                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

                        <div className="field embed-code">
                          <label>Embed code</label>
                          <input
                            type="text"
                            value={`[attachment:${attachment.id}]`}
                Severity: Major
                Found in app/javascript/components/Attachments/AttachmentEditor.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/ImageEditor/Form.tsx on lines 42..46

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

                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

                      <div className="field embed-code">
                        <label>Embed code</label>
                        <input type="text" value={`[image:${image.id}]`} disabled={true} />
                        {copySupported() && <button onClick={copyEmbedCode}>Copy</button>}
                      </div>
                Severity: Major
                Found in app/javascript/components/ImageEditor/Form.tsx and 1 other location - About 3 hrs to fix
                app/javascript/components/Attachments/AttachmentEditor.tsx on lines 98..106

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

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

                export default function GridImage(props: Props) {
                  const { attributeName, draggable } = props;
                  const record = draggable.record;
                  const image = record.image;
                
                
                Severity: Major
                Found in app/javascript/components/ImageGrid/GridImage.tsx - About 3 hrs to fix

                  Function Toolbar has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export default function Toolbar() {
                    const { state, dispatch } = useImageCropperContext();
                    const { cropping, image } = state;
                  
                    const aspectRatios: Array<[string, Crop.Ratio]> = [
                  Severity: Major
                  Found in app/javascript/components/ImageCropper/Toolbar.tsx - About 2 hrs to fix

                    Function applyTabs has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function applyTabs() {
                      const tabLinks: HTMLAnchorElement[] = Array.from(
                        document.querySelectorAll(".content-tabs li a")
                      );
                      const tabs: HTMLDivElement[] = Array.from(
                    Severity: Minor
                    Found in app/javascript/features/contentTabs.ts - 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

                    Severity
                    Category
                    Status
                    Source
                    Language