anyone-oslo/pages

View on GitHub

Showing 115 of 115 total issues

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

            <select
              name="locale"
              value={locale}
              onChange={(e) => setLocale(e.target.value)}>
              {Object.keys(locales).map((key) => (
Severity: Major
Found in app/javascript/components/Attachments/AttachmentEditor.tsx and 1 other location - About 1 hr to fix
app/javascript/components/ImageEditor/Form.tsx on lines 47..53

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

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

          <select name="locale" value={locale} onChange={handleChangeLocale}>
            {Object.keys(locales).map((key) => (
              <option key={`locale-${key}`} value={key}>
                {locales[key].name}
              </option>
Severity: Major
Found in app/javascript/components/ImageEditor/Form.tsx and 1 other location - About 1 hr to fix
app/javascript/components/Attachments/AttachmentEditor.tsx on lines 63..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 72.

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

export default function Image(props: ImageProps) {
  const imageSize = () => {
    const { image, cropping, crop_width, crop_height } = props.cropState;
    if (cropping) {
      return { width: image.real_width, height: image.real_height };
Severity: Minor
Found in app/javascript/components/ImageCropper/Image.tsx - About 1 hr to fix

    Function render has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      render() {
        const addChild = (id: TreeId, attributes: Attributes) => {
          const tree = this.state.tree;
          const index = tree.append(attributes, id);
          this.reorderChildren(id);
    Severity: Minor
    Found in app/javascript/components/PageTree.tsx - About 1 hr to fix

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

      export default function EditableImage(props: EditableImageProps) {
        const [image, setImage] = useState(props.image);
        const [src, setSrc] = useState(props.src);
      
        const openModal = useModalStore((state) => state.open);
      Severity: Minor
      Found in app/javascript/components/EditableImage.tsx - About 1 hr to fix

        Function FocalPoint has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function FocalPoint(props: FocalPointProps) {
          const { width, height, onChange } = props;
        
          const [dragging, setDragging] = useState(false);
          const [position, setPosition] = useState<Position>({
        Severity: Minor
        Found in app/javascript/components/ImageCropper/FocalPoint.tsx - 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 updateNodesPosition has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          updateNodesPosition() {
            let top = 1;
            let left = 1;
            const root = this.getIndex(1);
        
        
        Severity: Minor
        Found in app/javascript/lib/Tree.ts - About 1 hr to fix

          Function Toast has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export default function Toast(props: ToastProps) {
            const [fadeout, setFadeout] = useState(false);
            const { toasts, error, notice, next } = useToastStore((state) => state);
            const timerRef = useRef<number | null>(null);
          
          
          Severity: Minor
          Found in app/javascript/components/Toast.tsx - About 1 hr to fix

            Function TagEditor has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export default function TagEditor(props: TagEditorProps) {
              const [tags, setTags] = useState(props.tags);
              const [enabled, setEnabled] = useState(props.enabled);
            
              const tagList = [...tags, ...enabled].filter(onlyUnique);
            Severity: Minor
            Found in app/javascript/components/TagEditor.tsx - About 1 hr to fix

              Function useDragUploader has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              export default function useDragUploader(
                collections: DragCollection[],
                onDragEnd: (dragState: DragState, files: File[]) => void
              ) {
                const initialState: DragState = {
              Severity: Minor
              Found in app/javascript/components/drag/useDragUploader.ts - 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 renderEditNode has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                renderEditNode() {
                  const { dir, locale } = this.props;
              
                  const handleNameChange = (event: ChangeEvent<HTMLInputElement>) => {
                    this.setState({ newName: event.target.value });
              Severity: Minor
              Found in app/javascript/components/PageTree/Node.tsx - About 1 hr to fix

                Function render has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  render() {
                    return (
                      <div className="page-dates field">
                        <input
                          type="hidden"
                Severity: Minor
                Found in app/javascript/components/PageDates.jsx - About 1 hr to fix

                  Function build has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    build(obj: N): TreeIndex<N> {
                      const indexes = this.indexes;
                      const startId = this.cnt;
                  
                      const index = { id: startId, node: obj };
                  Severity: Minor
                  Found in app/javascript/lib/Tree.ts - About 1 hr to fix

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

                    export default function GridImage(props: GridImageProps) {
                      const { attributeName, draggable } = props;
                      const record = draggable.record;
                      const image = record.image;
                    
                    
                    Severity: Minor
                    Found in app/javascript/components/ImageGrid/GridImage.tsx - 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 Modal has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export default function Modal() {
                      const component = useModalStore((state) => state.component);
                      const close = useModalStore((state) => state.close);
                    
                      const handleClose = (evt: Event) => {
                    Severity: Minor
                    Found in app/javascript/components/Modal.tsx - About 1 hr to fix

                      Function uploadImage has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        const uploadImage = (file: File) => {
                          const validTypes = [
                            "image/gif",
                            "image/jpeg",
                            "image/pjpeg",
                      Severity: Minor
                      Found in app/javascript/components/ImageUploader.tsx - About 1 hr to fix

                        Function renderDateSelect has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          renderDateSelect(key, date, handleChange) {
                            return (
                              <div className="date-select">
                                <select
                                  value={date.getMonth()}
                        Severity: Minor
                        Found in app/javascript/components/DateRangeSelect.jsx - About 1 hr to fix

                          Function FileUploadButton has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export default function FileUploadButton(props: FileUploadButtonProps) {
                            const inputRef = useRef<HTMLInputElement>();
                          
                            const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
                              const fileList = evt.target.files;
                          Severity: Minor
                          Found in app/javascript/components/FileUploadButton.tsx - About 1 hr to fix

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

                            function containsFiles(evt: Event) {
                              if ("dataTransfer" in evt) {
                                const dataTransfer: DataTransfer = evt.dataTransfer;
                                if ("types" in dataTransfer) {
                                  const types = dataTransfer.types;
                            Severity: Minor
                            Found in app/javascript/components/drag/useDragUploader.ts - 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 render has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              render() {
                                const props = this.props;
                                const index = props.index;
                                const dragging = props.dragging;
                                const editing = this.node().editing;
                            Severity: Minor
                            Found in app/javascript/components/PageTree/Node.tsx - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language