I recently found out about GitHub actions superlinter which uses JSCPD to check for code duplication. It worked initially but I'm running into one specific false positive and I can't figure it out. JSCPD also has a package on npm and I tested it locally on that single file but it errored too. I have also tried adding new lines below but it didn't work too. The code and error are below.
Error:
2022-12-14 08:21:48 [INFO] File:[/github/workspace/components/pages/editor/sidebar/index.tsx]
2022-12-14 08:21:49 [ERROR] Found errors in [jscpd] linter!
2022-12-14 08:21:49 [ERROR] Error code: 1. Command output:
------
Clone found (tsx):
- /github/workspace/components/pages/editor/sidebar/index.tsx [40:7 - 58:3] (18 lines, 167 tokens)
/github/workspace/components/pages/editor/sidebar/index.tsx [37:7 - 51:2]
Clone found (tsx):
- /github/workspace/components/pages/editor/sidebar/index.tsx [40:7 - 58:3] (18 lines, 167 tokens)
/github/workspace/components/pages/editor/sidebar/index.tsx [37:7 - 51:2]
40 │ 37 │ <i className={"icon-search"}></i>
41 │ 38 │ </GenButton>
42 │ 39 │
43 │ 40 │ <GenButton props={{ label: "Sidebar: save" }}>
44 │ 41 │ <i className={"icon-floppy"}></i>
45 │ 42 │ </GenButton>
46 │ 43 │
47 │ 44 │ <GenButton props={{ label: "Sidebar: language" }}>
48 │ 45 │ <i className={"icon-globe"}></i>
49 │ 46 │ </GenButton>
50 │ 47 │
51 │ 48 │ <GenButton props={{ label: "Sidebar: launch" }}>
52 │ 49 │ <i className={"icon-rocket"}></i>
53 │ 50 │ </GenButton>
54 │ 51 │
55 │ 52 │ <GenButton props={{ label: "Sidebar: more info" }}>
56 │ 53 │ <i className={"icon-info-circled"}></i>
57 │ 54 │ </GenButton>
58 │ 55 │ </
Found 1 clones.
ERROR: jscpd found too many duplicates (11.18%) over threshold (0%)
Error: ERROR: jscpd found too many duplicates (11.18%) over threshold (0%)
at ThresholdReporter.report (/node_modules/#jscpd/finder/dist/reporters/threshold.js:12:19)
at /node_modules/#jscpd/finder/dist/in-files-detector.js:82:26
at Array.forEach (<anonymous>)
at /node_modules/#jscpd/finder/dist/in-files-detector.js:81:28
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
------
Code:
import { memo, useContext } from "react";
import ContextIndex from "../../../../utils/context/index";
import ContextGlobal from "../../../../utils/context/_global";
import GenButton from "../../../gen/button";
import GenImage from "../../../gen/image";
import EditorFileExplorer from "./fileExplorer";
import styles from "./index.module.css";
const EditorSidebar: React.FC = () => {
const { isLightTheme, setIsLightTheme, session } = useContext(ContextGlobal);
const {
barState: { leftBarOpen, explorerOpen },
updateBarState,
} = useContext(ContextIndex);
function handleAlert() {
alert("Hello World");
}
return (
<>
<section
className={
leftBarOpen ? styles.sidebarSectionOpen : styles.sidebarSection
}
>
<div className={`${styles.flexButtons} hoverParent`}>
<GenButton
props={{
label: "Sidebar: toggle file explorer",
onClick:
session?.user !== undefined
? () => updateBarState({ type: "explorerOpen" })
: handleAlert,
}}
>
<i className={"icon-docs"}></i>
</GenButton>
<GenButton props={{ label: "Sidebar: search" }}>
<i className={"icon-search"}></i>
</GenButton>
<GenButton props={{ label: "Sidebar: save" }}>
<i className={"icon-floppy"}></i>
</GenButton>
<GenButton props={{ label: "Sidebar: language" }}>
<i className={"icon-globe"}></i>
</GenButton>
<GenButton props={{ label: "Sidebar: launch" }}>
<i className={"icon-rocket"}></i>
</GenButton>
<GenButton props={{ label: "Sidebar: more info" }}>
<i className={"icon-info-circled"}></i>
</GenButton>
</div>
<div className={`${styles.flexButtons} hoverParent`}>
<GenButton props={{ label: "Sidebar: profile" }}>
{session?.user.image !== undefined ? (
<GenImage
props={{
src: session.user.image,
height: 40,
width: 40,
alt: session.user.name,
className: styles.profileImage,
}}
/>
) : (
<i className={"icon-user-circle"}></i>
)}
</GenButton>
<GenButton
props={{
label: "Sidebar: toggle theme",
onClick: () => setIsLightTheme((prev) => !prev),
}}
>
{isLightTheme ? (
<i className={"icon-toggle-off"}></i>
) : (
<i className={"icon-toggle-on"}></i>
)}
</GenButton>
<GenButton props={{ label: "Sidebar: settings" }}>
<i className={"icon-cog"}></i>
</GenButton>
</div>
</section>
{explorerOpen && <EditorFileExplorer />}
</>
);
};
export default memo(EditorSidebar);
Related
first of all my configuration:
nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
export default defineNuxtConfig({
// if you want to use static HTML generation (SSG)
target: 'static',
// if you want to use server-side rendering (SSR)
ssr: true,
css: [
'assets/scss/main.css',
'assets/scss/header.css',
'#fortawesome/fontawesome-svg-core/styles.css'
],
build: {
transpile: [
'#fortawesome/vue-fontawesome',
'#fortawesome/fontawesome-svg-core',
'#fortawesome/pro-solid-svg-icons',
'#fortawesome/pro-regular-svg-icons',
'#fortawesome/free-brands-svg-icons'
]
}
})
/plugins/fontawesome.js
import { defineNuxtPlugin } from '#app';
/** Fontawesome for Nuxt 3
* https://fontawesome.com/docs/web/use-with/vue/use-with#nuxt
*
*/
// import the fontawesome core
import { library, config } from '#fortawesome/fontawesome-svg-core'
// import font awesome icon component
import { FontAwesomeIcon } from '#fortawesome/vue-fontawesome'
// import specific icons
import { fas } from '#fortawesome/free-solid-svg-icons'
// This is important, we are going to let Nuxt worry about the CSS
config.autoAddCss = false
export default defineNuxtPlugin((nuxtApp) => {
console.log('[Plugin]', 'Font Awesome')
// You can add your icons directly in this plugin. See other examples for how you
// can add other styles or just individual icons.
library.add(fas);
nuxtApp.vueApp.component('font-awesome-icon', FontAwesomeIcon)
})
<template>
<header class="header">
<Logo />
coffee <font-awesome-icon icon="fas coffee" />
flag <font-awesome-icon icon="fas fa-flag" />
search <font-awesome-icon icon="fas fa-magnifying-glass" />
search 2 <font-awesome-icon icon="fa-solid fa-magnifying-glass" />
<nav>
<nuxt-link :to="{ path: '/' }">
Home
</nuxt-link>
<nuxt-link :to="{ path: '/getting-started' }">
Getting Started
</nuxt-link>
<nuxt-link :to="{ path: '/faq' }">
FAQ
</nuxt-link>
<nuxt-link :to="{ path: '/search' }">
<font-awesome-icon icon="fas fa-magnifying-glass" />
</nuxt-link>
</nav>
</header>
</template>
Problem
When I start npx nuxi dev and look at the page via localhost, the icons appear for 1 second and then are no longer visible. I have been searching for a solution for quite some time because I could not find an error right away.
Warning - console
[Vue warn]: Hydration node mismatch:
- Client vnode: font-awesome-icon
- Server rendered DOM: <svg class="svg-inline--fa fa-magnifying-glass" style aria-hidden="true" focusable="false" data-prefix="fas" data-icon="magnifying-glass" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">…</svg>
at <Navigation>
at <Default >
at <AsyncComponentWrapper >
at <BaseTransition mode="out-in" appear=false persisted=false ... >
at <Transition name="layout" mode="out-in" >
at <Anonymous>
at <App key=1 >
at <NuxtRoot>
You can wrap the component in a <client-only>, so it only renders client-side.
<client-only>
<font-awesome-icon icon="fas fa-flag" />
</client-only>
I have a class component that I am trying to style the elements, the buttons, textboxes etc. To those ends I followed this link https://react-bootstrap.github.io/getting-started/introduction to install bootstrap in my react then i have import Button from 'react-bootstrap/Button'; and import 'bootstrap/dist/css/bootstrap.min.css'; in my header.
.
If I use <button type="submit">Submit</button> I notice that my button has no style at all and looking at examples I see everyone using <Button bsStyle="primary" bsSize="large" disabled>Test</Button> except that, when I do I get the error Error: Invalid hook call. Hooks can only be called inside of the body of a function component. Since I am using a class component, does that mean I have to rewrite the entire thing to a function? But also I see the example on this link https://www.golangprograms.com/how-to-use-react-bootstrap-component.html using a class.
Appreciate if I be assisted in this regard.
Regards
import React, { Component } from 'react'
import Button from 'react-bootstrap/Button';
import 'bootstrap/dist/css/bootstrap.min.css';
class Transport extends Component {
constructor(props) {
super(props)
this.state = {
dieselTxt: '',
electricTxt: '',
gasolineTxt: '',
vehMaintain: '',
gasolineCarbon:''
}
}
handDieselChange = (event) => {
this.setState({
dieselTxt: event.target.value
})
}
handElectricChange = (event) => {
this.setState({
electricTxt: event.target.value
})
}
handGasTxtChange = (event) => {
this.setState({
gasolineTxt: event.target.value
})
}
handBusTxtChange = (event) => {
this.setState({
BusTxt: event.target.value
})
}
handTrainTxtChange = (event) => {
this.setState({
trainTxt: event.target.value
})
}
handFlightTxtChange = (event) => {
this.setState({
flightTxt: event.target.value
})
}
handVenSelectChange = (event) => {
this.setState({
vehMaintain: event.target.value
})
}
vehiclesCarbon = (event) => {
alert("test");
if (`${this.state.vehMaintain}` === '1') {
//` 22 / miles per galon(21.6) )* EF_passenger_vehicle*(nonCO2_vehicle_emissions_ratio)`
const estLBCarbonGas = ((this.state.gasolineTxt / 21.6) * 19.6* 1.01).toFixed(0);
this.setState({ gasolineCarbon: estLBCarbonGas })
}
event.preventDefault()
}
render() {
const { dieselTxt, electricTxt, gasolineTxt, vehMaintain, gasolineCarbon,trainTxt, BusTxt, flightTxt } = this.state
return (
<div>
<h4>Enter your vehicle's yearly milage</h4>
<form onSubmit={this.handleSubmit}>
<div>
<label>Gasoline </label>
<input type="text"
value={gasolineTxt}
onChange={this.handGasTxtChange}
/>
</div>
{/* <div>
<label>Diesel</label>
<input type="text"
value={dieselTxt}
onChange={this.handDieselChange}
/>
</div>
<div>
<label>Electric</label>
<input type="text"
value={electricTxt}
onChange={this.handElectricChange}
/>
</div> */}
<div>
<label>Do you perform regular maintenance on your vehicle?</label>
<select value={vehMaintain}
onChange={this.handVenSelectChange}>
<option value=""></option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
</div>
<div>
<input type="text"
value={gasolineCarbon}
/>
</div>
{/* <p>Public Transporation</p>
<div>
<label>Bus </label>
<input type="text"
value={BusTxt}
onChange={this.handBusTxtChange}
/>
</div>
<div>
<label>Train </label>
<input type="text"
value={trainTxt}
onChange={this.handTrainTxtChange}
/>
</div>
<p>Air Travel</p>
<div>
<label>Flights </label>
<input type="text"
value={flightTxt}
onChange={this.handFlightTxtChange}
/>
</div> */}
<div>
<button onClick={this.vehiclesCarbon}>Test</button>
<Button bsStyle="primary" bsSize="large" disabled>
Primary button
</Button>
</div>
</form>
</div>
)
}
}
export default Transport
Tab
import { useState } from "react";
import EnergyConsum from "./EnergyConsum";
import Transport from "./Transport";
import WasteForm from "./WasteForm";
//import "./App.css";
function Tabs() {
const [toggleState, setToggleState] = useState(1);
const toggleTab = (index) => {
setToggleState(index);
};
return (
<div className="container">
<div className="bloc-tabs">
<button
className={toggleState === 1 ? "tabs active-tabs" : "tabs"}
onClick={() => toggleTab(1)}
>
Energy Consumption
</button>
<button
className={toggleState === 2 ? "tabs active-tabs" : "tabs"}
onClick={() => toggleTab(2)}
>
Transport
</button>
<button
className={toggleState === 3 ? "tabs active-tabs" : "tabs"}
onClick={() => toggleTab(3)}
>
Tab 3
</button>
</div>
<div className="content-tabs">
<div
className={toggleState === 1 ? "content active-content" : "content"}
>
<h5>How much energy do you consume</h5>
<hr />
<EnergyConsum />
</div>
<div
className={toggleState === 2 ? "content active-content" : "content"}
>
<h2>How do you get around</h2>
<hr />
<Transport />
</div>
<div
className={toggleState === 3 ? "content active-content" : "content"}
>
<h2>Content 3</h2>
<hr />
<WasteForm />
</div>
</div>
</div>
);
}
export default Tabs;
Index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
reportWebVitals();
Full Error Message
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
▶ 21 stack frames were collapsed.
Module.<anonymous>
H:/Documents/Projects/Solidity/MYCFC/my-cfc/src/index.js:8
5 | import reportWebVitals from './reportWebVitals';
6 |
7 |
> 8 | ReactDOM.render(
9 | <React.StrictMode>
10 | <App />
11 | </React.StrictMode>,
View compiled
Module../src/index.js
http://localhost:3001/static/js/main.chunk.js:2365:30
__webpack_require__
H:/Documents/Projects/Solidity/MYCFC/my-cfc/webpack/bootstrap:856
853 |
854 | __webpack_require__.$Refresh$.init();
855 | try {
> 856 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 857 | } finally {
858 | __webpack_require__.$Refresh$.cleanup(moduleId);
859 | }
View compiled
fn
H:/Documents/Projects/Solidity/MYCFC/my-cfc/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
1
http://localhost:3001/static/js/main.chunk.js:2501:18
__webpack_require__
H:/Documents/Projects/Solidity/MYCFC/my-cfc/webpack/bootstrap:856
853 |
854 | __webpack_require__.$Refresh$.init();
855 | try {
> 856 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 857 | } finally {
858 | __webpack_require__.$Refresh$.cleanup(moduleId);
859 | }
View compiled
checkDeferredModules
H:/Documents/Projects/Solidity/MYCFC/my-cfc/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 |
View compiled
Array.webpackJsonpCallback [as push]
H:/Documents/Projects/Solidity/MYCFC/my-cfc/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;
View compiled
(anonymous function)
http://localhost:3001/static/js/main.chunk.js:1:65
I am currently having a problem of calling the server-side code on SQL data, the client-side always get called first and I will have to wait for around 5 minutes or more for the server-side to be invoked. On a few occasions, the server-side is not called. Here are the rough code and file structure. is there a way to call the server-side without waiting for long?
statistics.html, page to call the server
<template name="statistics">
<div class="content">
<h2>HTML Forms</h2>
<div class="row">
<div class = "col-lg-2">
<button type="button" class="btn btn-primary getdata" >Get stats</button>
</div>
</div>
</div>
</template>
statistics.js, to call getData function
Template.statistics.events({
'click .getdata'(event, instance){
alert("get data")
Meteor.call('getSqlData', function(err, response) {
if(err){
console.log("err is "+err)
}
console.log(response);
});
}
});
sqlData.js, function getSqlData
Meteor.methods({
getSqlData: function(){
console.log("at sqldata");
if(Meteor.isClient){
console.log("shouldn't be here")
}
if(Meteor.isServer){
console.log("server side")
//go to a directory and get the file names to be read
//get the data in the files and insert into mongoDB
}
});
my file structure is place in this manner
Project
├── imports
│ ├── ui
│ │ ├── pages
│ │ │ ├── statistics.js
│ │ │ ├── statistics.html
├── lib
│ ├── collections
│ │ ├── sqlData.js
I have a Blueimp gallery working, but when the page loads, it immediately goes to slideshow mode, instead of only displaying the thumbnails.
I'd like to display thumbnails first, so that if someone wants to start in the middle of the show they can easily do that.
How can I stop it from automatically going to slideshow mode?
Here is my html
18 <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-start-slideshow="false">
19 <!-- The container for the modal slides -->
20 <div class="slides"></div>
21 <!-- Controls for the borderless lightbox -->
22 <h3 class="title"></h3>
23 <p class="description"></p>
24 <a class="prev">‹</a>
25 <a class="next">›</a>
26 <a class="close">×</a>
27 <a class="play-pause"></a>
28 <ol class="indicator"></ol>
29 <!-- The modal dialog, which will be used to wrap the lightbox content -->
30 <div class="modal fade">
31 <div class="modal-dialog">
32 <div class="modal-content">
33 <div class="modal-header">
34 <button type="button" class="close" aria-hidden="true">×</button>
35 <h4 class="modal-title"></h4>
36 </div>
37 <div class="modal-body next"></div>
38 <div class="modal-footer">
39 <button type="button" class="btn btn-default pull-left prev">
40 <i class="glyphicon glyphicon-chevron-left"></i>
41 Previous
42 </button>
43 <button type="button" class="btn btn-primary next">
44 Next
45 <i class="glyphicon glyphicon-chevron-right"></i>
46 </button>
47 </div>
48 </div>
49 </div>
50 </div>
51 </div>
60 <div id="links">
61 #foreach ($finalQuery as $image)
62 <a href="{{ URL::route ('ppMiscGetProtectedFile', [ 'fileID' => $image['fileID'], 'size' => 'original' ] ) }}"
63 title="{{ $image['image_number'] }}"
64 data-description="Year: {{ $image['year'] }}"
65 data-gallery
66 >
67 <img src="{{ URL::route( 'ppMiscGetProtectedFile', [ 'fileID' => $image['fileID'], 'size' => 'thumbSmall'] ) }}" alt="{{ $image['image_number'] }}" />
68 </a>
69 #endforeach
70
71 </div>
And here is the Javascript
78 <script src="//blueimp.github.io/Gallery/js/jquery.blueimp-gallery.min.js"></script>
79 <script src="/js/bs_gallery/blueimp-gallery.min.js"></script>
80
86 <script>
87 blueimp.Gallery(
88 document.getElementById('links').getElementsByTagName('a'),
89 {
90 startSlideshow:false,
91 onslide: function (index, slide) {
92 var text = this.list[index].getAttribute('data-description'),
93 node = this.container.find('.description');
94 node.empty();
95 if (text) {
96 node[0].appendChild(document.createTextNode(text));
97 }
98 }
99 }
100 );
101
102
103 var options = {
104 startSlideshow: false,
105 };
106
107
108
109
110 </script>
It works, I get the gallery and I get the description field showing up (the Year: tag). It took a while to figure out how to get the description field to show. The blueimp documentation code doesn't work, but searching stack exchange got that fixed.
But now it always starts in slideshow mode. How do I get it to default to displaying the wall of thumbnails instead?
The reason it starts immediately is that you are creating the gallery instance as soon as the script loads. The way to load the thumbnail view first is to put the gallery initializer code inside a click handler set up on the thumbnail images.
Example:
<script>
document.getElementById('links').onclick = function (event) {
event = event || window.event;
var target = event.target || event.srcElement,
link = target.src ? target.parentNode : target,
options = { index: link, event: event},
links = this.getElementsByTagName('a');
blueimp.Gallery(links, options);
};
</script>
Also, the startSlideshow option is for controlling whether the slideshow begins when the gallery launches, which I think is different than what you are after.
Since I turned off autopublish, as one should as its unrealistic in the real world, my templates stopped rendering collections (#each seems to loop over nothing).
I've set up a manual publish/subscribe for the collection, and I can see the local collection has items in it when I log it to the console, yet the template fails to render the items.
Is there anything I need do to when manually sub/pub-ing collections in order to keep the template's auto updating nature?
Here's a diluted test case I've created:
// client
Col = new Meteor.Collection('testcol');
// I have tried wrapping this in autosubscribe as well:
Meteor.subscribe('testcol', function() {
return Col.find();
});
Template.hello.items = function() {
var col = Col.find();
if (col) {
console.log("Test items" , col);
return col.fetch().items;
}
}
// server
if (Meteor.is_server) {
Col = new Meteor.Collection('testcol');
Meteor.publish('testcol', function() {
return Col.find();
})
}
// bootstrap:
Meteor.startup(function () {
if (Col.find().count() < 5) {
for (var i=0; i<5; i++) {
Col.insert({
title: 'Test ' + i,
items: [
{title: 'item 1', value:true},
{title: 'item 2', value:false},
{title: 'item 3', value:true}
]
});
}
}
})
// Template
<head>
<title>test</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<h1>Where did the data gone to?</h1>
Items from the test collection:
<UL>
{{#each items}}
<LI> ITEM: {{title}}
{{/each}}
</UL>
</template>
The Meteor version of #each expects a Cursor or an Array as your codes points items as this is a child attribute of each document your function returns undefined so you'll need to loop over all Docs then items or findOne({_id:???}) loop of it's items;
So the following works (favouring version 1) for returning all docs in the collection:
return col.find()
return col.find().fetch()
Also you should only be declaring the collection once in a common script then pub/sub in the respective Working code below, post back if you have questions.
.html
1 <head>
2 <title>test</title>
3 </head>
4
5 <body>
6 {{> hello}}
7 </body>
8
9 <template name="hello">
10 <h1>Where did the data gone to?</h1> 11 Items from the test collection:
12 <ul id="docs">
13 {{#each docs}}
14 <li>Doc: {{title}}
15 <ul class="items">
16 {{#each items}}
17 <li>Item: {{title}}</li>
18 {{/each}}
19 </ul>
20 </li>
21 {{/each}}
22 </ul>
23 </template>
.js
1 // client
2 //
3 Col = new Meteor.Collection('testcol');
4 //
5 // // I have tried wrapping this in autosubscribe as well:
6 if(Meteor.is_client){
7 Meteor.subscribe('testcol');
8
9 Template.hello.docs = function() {
10 return Col.find();
11 }
12 }
13
14
15 // server
16
17 if (Meteor.is_server) {
18
19 Meteor.publish('testcol', function() {
20 return Col.find();
21 });
22 }
23
24
25 // bootstrap:
26
27 Meteor.startup(function () {
28 if (Col.find().count() < 5) {
29 for (var i=0; i<5; i++) {
30 Col.insert({
31 title: 'Test ' + i,
32 items: [
33 {title: 'item 1', value:true},
34 {title: 'item 2', value:false},
35 {title: 'item 3', value:true}
36 ]
37 });
38 }
39 }
40 });