I tried to install SwiftLint using CocoaPods and I add in Build phases the following script :
"${PODS_ROOT}/SwiftLint/swiftlint"
SwiftLint is installed correctly and I get many errors and warnings in the project.
Then, I create the swiftLint.yml file in which I modify some rules but they are not token into consideration and the same number of errors and warnings persist in Xcode project.
When I run this command to confirm the application of the rules :
./swiftlint lint --config .swiftlint.yml
I get the error :
No lintable files found at paths : ''
How can I solve this issue please?
It happens also if you rename the directory of your app, make sure you report the change in the .swiftlint.yml too at first lines :
included: # paths to include during linting
- My_App_Directory
For those of you who used 0.42.0 before and updated to 0.43.0 (or higher?).
They made a change and now interpret included and excluded as relative paths.
Configuration files now consistently have their included/excluded
relative file paths applied relative to their location in the file
system. Previously the root configuration file applied these relative
to the current working directory, but nested configurations applied
these to their location in the file system.
From the release notes of 0.43.0: Clothes Line Interface.
if you are using swiftLint with CocoaPods : try "${PODS_ROOT}/SwiftLint/swiftlint" --config .swiflint.yml in your SwiftLint Run Script in your project build phases.
make sure your .swiflint.yml config file is in the root of your project directory ( beside .xcodeproj file ).
make sure the paths included on your .swiflint.yml (in included: and excluded: sections ) is valid paths
make sure your .swiflint.yml file is valid yaml
don't escape the directory paths in your config file
dont do : - some\ Directorybut do - some Directory without escape character.
If you installed it using Cocoapods this can help you.
I will just merely improve the above answers, to put clarity on how to resolve the issue of SwiftLint not finding the path.
Things to lookout for.
Make sure your swiftlint.yml file is valid.
Make sure the swiftlint.yml is in the same level as your .xcodeproj
Don't specify --path and also add an entry under included: inside your yml file, choose one, either specify the --path or add an entry don't use both otherwise SwiftLint will ignore the --path param, and if the entry specified inside included: is wrong you will get the "no lintable file found" error
In your script.
The gihub page of SwiftLint recommends just using "${PODS_ROOT}/SwiftLint/swiftlint" but that didn't work for me, I had to specify the --path see below for the full script.
"${PODS_ROOT}/SwiftLint/swiftlint" --path "${SRCROOT}/Classes" --config "directory-of-your-config"
The --path param should be your own --path "${SRCROOT}/Classes"
Finally inside the yml file.
Make sure your included and excluded file specification is correct, see how I did mine below.
included:
- Your-Project-Name
excluded:
- Pods
One Important thing to note is if you add directories under included: the --path param will be ignored, and you might possibly get the "no lintable files found" error if the directory is wrong.
First of all, you do not need to add explicitly the--config file if the yml file is in the running directory (from where you are running the command) and name is .swiftlint.yml.
Secondly, you need to specify the path for your source with --path. Below command will work fine in your case,
swiftlint lint --path SourcePath
For swiftlint from version 0.41 the following code worked for me in the build phase (workspace with several projects. Depending on the project configuration, it may be that "../" has to be removed from the path information):
cd ${PROJECT_DIR}/../
"${PODS_ROOT}/SwiftLint/swiftlint" --config "${PROJECT_DIR}/../.swiftlint.yml"
Here is a screenshot of the build phase entry:
Replace autocorrect with --fix
export PATH="$PATH:/opt/homebrew/bin" //This line is only for Apple Silicon chips
if which swiftlint > /dev/null; then
swiftlint --fix && swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
For M1, don't go for swift lint installation VIA PODS instead use Brew.
For installation run below command in Terminal
brew install swiftlint
and add below scripts into RunScript into build phase of your target.
export PATH="$PATH:/opt/homebrew/bin"
if which swiftlint > /dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
If you using pod file then follow this steps:
Run Script: "${PODS_ROOT}/SwiftLint/swiftlint"
This worked for me
if which "${PODS_ROOT}/SwiftLint/swiftlint" >/dev/null; then
${PODS_ROOT}/SwiftLint/swiftlint --fix && ${PODS_ROOT}/SwiftLint/swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Related
These are the commands that were used:
$ source /opt/ros/foxy/setup.bash
ROS_DISTRO was set to 'noetic' before. Please make sure that the environment does not mix paths from different distributions.
$ export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3_simulations/turtlebot3_gazebo/models
$ export TURTLEBOT3_MODEL=burger
$ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
Package 'turtlebot3_gazebo' not found: "package 'turtlebot3_gazebo' not found, searching: ['/opt/ros/foxy']"
Is it possible that a sub-directory is missing in the path?
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models
Alternatively, you may use the following if you do not require a workspace:
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/foxy/share/turtlebot3_gazebo/models
my swiftlint.yml file is not excluding my "Generated Mocks" folder. I've tried Generated\ Mocks and 'Generated Mocks' Is there a solution to this?
excluded:
- Pods
- MyProjectTests
- MyProject/Helpers/Constants.swift
- Generated Mocks
edit: The Generated Mocks folder was generated from a dependency I added so I hope that helps
Instead of writing excluded commands in swiftlint.yml file, simply use included command and add your project path, tests etc. in here (paths where you want your swiftlint to run).
For instance, my swiftlint.yml file looks like this:
included:
- [PROJECT_NAME]
- [PROJECT_NAME]Tests
- [PROJECT_NAME]UITests
I only have a included command and I added paths where I want my swiftlint rules to work.
Make sure to add this command:
if which swiftlint >/dev/null; then
swiftlint --config [PROJECT_PATH]/.swiftlint.yml
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
to:
Target > Build Phases > Run Script
And lastly, make sure that your .swiftlint.yml file is located of your project's root path.
Build the project, you'll see that your SwiftLint warnings will show only for your included folders & files.
Another approach would be to change the destination folder name from Genera†ed Mocks to GeneratedMocks, and then use this in .yaml (works for me):
excluded:
- Pods
- UnitTests/generated/GeneratedMocks.swift
I'm experimenting with yarn 2 and faceplanting.
I created a new folder: /projects/yarn2/
As per their install guide https://yarnpkg.com/getting-started I ran
cd /projects/yarn2/
yarn set version berry
yarn init
then (as per their guide https://yarnpkg.com/getting-started/usage )
yarn add react
and got the following error:
Usage Error: The nearest package directory (/projects/yarn2) doesn't seem to be part of the project declared in /projects.
- If the project directory is right, it might be that you forgot to list yarn2 as a workspace.
- If it isn't, it's likely because you have a yarn.lock or package.json file there, confusing the project root detection.
$ yarn add [--json] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] ...
What am I doing wrong?
You either don't have package.json or yarn.lock which confuses yarn if the package is added in the workspace or not. Just run the following command and I think your problem must be solved.
cd <folder_name>/<project_name>
touch yarn.lock
yarn
Check to see if you have a package.json or yarn.lock file in your /projects directory. If you do, clear it/them out and this should start working.
To add to the previous answers what worked for me was:
It seems to be that yarn.lock file is what's really required, so if you have started with yarn v1.x and did yarn init - then you will have a package.json file in the project dir already.
If you now switch over to yarn v2 by doing yarn set berry, and want to add a package by yarn add [whatever] it will fail. You can work around that by creating an empty file by: touch yarn.lock (or on windows just cat '' > yarn.lock) after that it should work fine.
I figured out an even better / faster way to do it now, just do this in an empty project folder:
yarn init -2
this will initialize a new yarn v2 project folder with .yarnrc.yml, package.json, and the .yarn folder, also initializes an empty .git folder and adds a proper .gitignore. check by yarn --version - should echo v2.x.x
Usage Error: The nearest package directory (/<path_to_folder>/<project_name>) doesn't seem to be part of the project declared in /<path_to_folder>.
Solution:
Search for yarn.lock and package.json files inside /<path_to_folder> and delete them!
you have to remove yarn.lock and package.json file in your root directory ,some times there may be .yarnrc yarnyml files in you root directory you have to remove them also.
I am looking to disable a couple of SwiftLint rules for the unit tests within my application.
For example I am wanting to disable the weak_delegate rule for my unit tests.
Having looked at the SwiftLint docs I think it may be possible by defining a custom weak_delegate rule and excluding the path to my unit tests.
https://github.com/realm/SwiftLint#defining-custom-rules
You can disable them at a local level using:
//swiftlint:disable weak_delegate
let someDelete: someDelegate?
//swiftlint:enable weak_delegate
or at target level, by modifying your .swiftlint.yml file (hidden)
weak_delegate:
excluded: ".*Test\\.swift" //regex path to your tests folder
or at project level, by modifying your .swiftlint.yml file (hidden)
disabled_rules:
- weak_delegate
Best way to exclude some rules for test target is the nested configuration: you add a second .swiftlint.yml to root of your tests directory with rules to disable.
disabled_rules:
- weak_delegate
- cyclomatic_complexity
- force_unwrapping
- function_body_length
Add this to your .swiftlint.yml:
weak_delegate:
excluded: ".*Test\\.swift" //regex path to your tests folder
Change the script in Build Phases to point only to the folder of your source code:
if which swiftlint > /dev/null; then
swiftlint --path "$SRCROOT"/[name_of_source_folder]
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Adding the flag --path "$SRCROOT"/path_to_folder will exclude the test targets.
I use Eclipse CDT to auto generate make files. Now I've added some make flags to create coverage information which results in *.gcno files being created when building. When cleaning my project only *.d and *.o files are removed. What I wonder is how to extend clean to also remove *.gcno files while still letting Eclipse auto generate my make files.
Cheers,
Ceqvi
I had the same problem, and you gave me an idea that works much better:
In Makefile.targets:
clean: clean-gcov
clean-gcov:
-$(RM) $(foreach subdir,$(SUBDIRS),$(wildcard $(subdir)/*.gcda) $(wildcard $(subdir)/*.gcno))
Running it:
$ make clean
rm -rf src/Hello.gcda src/Hello.gcno
rm -rf ./src/test/HelloTest.o ./src/Hello.o ./src/test/HelloTest.d ./src/Hello.d test