TSlint: 'let' and 'const' triggers forbidden 'var' keyword error - tslint

I'm running TSLint (v5.3.2) with my typescript project. I'm getting Forbidden 'var' keyword, use 'let' or 'const' instead but I'm not using 'var' and it points to my use of 'let' or 'const'.
For example, here's a codeFrame format of the error to show I'm using 'const' and not 'var':
Forbidden 'var' keyword, use 'let' or 'const' instead (no-var-keyword)
58 | .map((response) => {
59 | // update the login status
> 60 | const tokensValid = response['isvalid'] === true;
| ^
61 | if (tokensValid) {
62 | this.loggedIn$.next(true);
63 | return true;
So far I haven't been able to figure out why I'm getting this error. Any ideas?
Thanks.

Turns out to be an issue with yarn 1.1.0. Downgraded to yarn 1.0.1 and tslint started passing again. Have not determine exactly what changed between the two versions that caused the issue.

Just encountered this problem with webpack, tslint-loader and awesome-typescript-loader. I solved it by doing this (simplified):
module: {
rules: [
{
test: /\.tsx?$/,
enforce: 'pre', // this little bugger
loader: 'tslint-loader',
},
{
test: /\.tsx?$/,
use: ['awesome-typescript-loader'],
},
],
},

This seems to be an error with TSlint itself. I would recommend you to deactivate this rule on the tslint.json config and see if it works.
{
"rules": {
"no-var-keyword": true
}
}
In case it does not work it might be an error with your IDE or something. Hope this helps you out.

Adding npx to the command did the trick for me:
npx tslint -c tslint.json -p tsconfig.json
(Using Yarn 1.16.0)

Related

Can't get tagging to work with cypress-cucumber-preprocessor

I am currently having issues with using tagging with the cypress-cucumber-preprocessor package. I know that the cypress-tags has been removed and made redundant so I'm trying to set up tagging using the new syntax but to no avail.
Here is my feature:
Feature: duckduckgo.com
Rule: I am on a desktop
Scenario: visiting the frontpage
When I visit <site>
Then I should see a search bar
#google
Examples:
| site |
| google.com |
#duckduckgo
Examples:
| site |
| duckduckgo.com |
And my step definitions:
import { When, Then } from "#badeball/cypress-cucumber-preprocessor";
When(`I visit` + url, () => {
if(url === 'duckduckgo.com') return cy.visit("https://www.duckduckgo.com");
if(url === 'google.com') return cy.visit("https://www.google.com");
});
Then("I should see a search bar", () => {
cy.get("input").should(
"have.attr",
"placeholder",
"Search the web without being tracked"
);
});
When I try to run my tests with npx cypress run --env tags="#google", it gives me an error saying url in my steps definitions isn't defined. What am I doing wrong?
Try to add script with this command in package.json file this way:
"scripts": {
"open:test": "npm run clean:report && cypress open --env configFile=test,TAGS=#test" (or any tag you need)
}
And then use it as:
npn run open:test
The main difference besides rapping it into script is not using quotes, maybe this will help you

Substrate Build a dApp Tutorial - TypeError: Cannot read property 'query' of undefined

I was able to to run a local substrate node on my machine, finishing the first few tutorials - but am running into a problem with the "build-a-dapp" tutorial (https://substrate.dev/docs/en/tutorials/build-a-dapp/).
Its possible to successfully run the adjusted node. Building the custom front end is something of a two step process in the tutorial.
First running the "old" front end used in the very first build-your-own-node tutorial. Which is then started with yarn start - works fine. Afterwards the App.js file is adjusted, after saving it should switch to the new setup with the PoE UI elements. However, it drops the following error message for me:
TypeError: Cannot read property 'query' of undefined
142 | export default function TemplateModule (props) {
143 | const { api } = useSubstrate();
> 144 | return (api.query.templateModule && api.query.templateModule.proofs
145 | ? <Main {...props} /> : null);
146 | }
Compiled version:
212 | const {
213 | api
214 | } = Object(_substrate_lib__WEBPACK_IMPORTED_MODULE_2__["useSubstrate"])();
> 215 | return api.query.templateModule && api.query.templateModule.proofs ? /*#__PURE__*/Object(react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_5__["jsxDEV"])(Main, { ...props
| ^ 216 | }, void 0, false, {
217 | fileName: _jsxFileName,
218 | lineNumber: 145,
I run it on iOS, all the other tutorials worked just fine, I already deleted everything and worked myself again through the tutorial to make sure I did not miss anything - is there any issue with the call of templateModule? Would appreciate any kind of help in this issue.
Cheers,
Martin

react-i18next cannot resolve key

I have a problem with react-i18next not resolving my keys, so everything I get as an output are the keys themself.
I had to embed my project as gui project to a VisualStudio solution. Running my original project works just fine, the solution project in contrast cannot resolve the key part of my translate function call.
t('user:KEY_CONSTANT') //output: KEY_CONSTANT
My i18n.config looks like this:
i18n
.use(XHR)
.init({
lng: i18nHelper.languageDetector(),
load: 'currentOnly',
fallbackLng: 'en-US',
backend: {
loadPath: 'i18n/{{lng}}/{{ns}}.json'
},
ns: ['admin', 'user'],
defaultNS: 'admin',
debug: false,
interpolation: {
escapeValue: false,
formatSeparator: ',',
format: function (vale, format, lng) {
if (format === 'uppercase') return value.toUpperCase();
return value;
}
}
});
When embedding the project in the solution, I had to change webpacks output folder, which I think is the actual reason of malfunctioning, but I can't find where exact the problem occurs. I tried changing the loadPath, but if thats the source of failure, I just didn't try it the right way :S
My project tree looks like:
Solution
|-gui
| |-src
| |-i18n
| |-de-DE(containing the german admin.json and user.json files)
| |-en-US(containing the english admin.json and user.json files)
| |-utils
| |-i18n.js
|-out
| |-prgFiles
| |-html
| |-i18n(contains same items as i18n under src)
In my old project, the webpack output was '/dist/' on the same level as src, in the solution, '../out/prgFiles/html'.
admin.json right now contains no keys at all, user.json contains the keys just like you'd expect:
{
"KEY_CONSTANT": "Actual string value"
}
As said, I tried around a bit with path changes, checked for translate, i18next and i18next-Provider beeing found and everythings fine. It just cant resolve KEY_CONSTANT to the actual value.
Do you have an idea what the problem might be?
set debug option to true in i18next init -> i bet you will get an error stating something like backendConnector failed to load namespace user...
make sure the clientside is able to load the translations (the webpack-dev server does a good job in doing so - but in production you will need to serve those file yourself)

`Tslint --fix` does not autofix but instead generates lint problems as console errors

I'm using the Angular starter kit
and I'm trying to get tslint to autofix all my lint problems with the --fix flag.
I'm running the script:
npm run tslint --fix src/**/*.ts
It just generates the same error that I'm already being told about in tslint and not autofixing it:
console output:
ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from'
Am I missing something that allows it to implement the changes?
My versions are:
"tslint": "^5.6.0"
"codelyzer": "^3.1.2"
Question: How can I get tslint to implement autofix to my lint errors?
Unfortunately, not all linting violations are auto-fixable. You can see which rules are auto-fixable here by looking for the Has Fixer tag.
My guess is that "comment must start with a space" is governed by the comment-format rule, which is not auto-fixable.
I'm not sure which rule is causing your second error, but it is most likely also not auto-fixable.
Here's a snippet you can run tslint --fix against to verify that some violations are fixed, and others are not.
//no var keyword (comment does not start with space)
var x: string = 'x';
console.log(x);
// array-type
let y: String[] = [];
console.log(y);
// ban-single-arg-parens
['1', '2'].filter((arg) => {
console.log(arg);
});
// semicolon
let z: string = ''
console.log(z);
// no unused variable
let a: string = '';
// trailing comma
let list = ['1', '2', ];
// missing trailing comma
let obj = [
1,
2
];
Rules to include when linting the above file:
"semicolon": [true, "always"],
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}],
"array-type": [true, "array-generic"],
"arrow-parens": [true, "ban-single-arg-parens"],
It's tempting to think that all whitespace errors would be auto-fixable, and perhaps they should be. Sadly, they're not.
Update library tslint and codelyzer to latest.
and then use this command:
tslint --fix src/**/*.ts -t verbose without using npm run
after complete, it will show to you the unfixable problems so you have to fix it manually.
You can also add it to scripts in package.json like this:
"lint-fix": "tslint --fix src/**/*.ts -t verbose"

Puppet syntax error at '|'

I seem to have run into a syntax error on a previously-working puppet manifest. This is running on a local vagrant box with Ubuntu 12.04, and Puppet version 3.4.2. The puppet stuff was all generated at puphpet.com.
The error I'm getting is:
Error: Could not parse for environment production: Syntax error at '|'
at /tmp/vagrant-puppet/manifests/default.pp:263:29 on node
vagrant.example.com
Line 263 of default.pp is the second line of this snippet:
if count($php_values['ini']) > 0 {
$php_values['ini'].each { |$key, $value|
puphpet::ini { $key:
entry => "CUSTOM/${key}",
value => $value,
php_version => $php_values['version'],
webserver => $php_webserver_service
}
}
}
It looks like you haven't set parser to future.
Run this command:
puppet config print parser
If it returns current, you don't have access to the .each function. To change this, edit /etc/puppet/puppet.conf, and put parser = future under the [main] block. The above command should then return future.
Reference: http://docs.puppetlabs.com/references/latest/function.html#each

Resources